partitioncloud-server/scripts/hooks/utils.py

28 lines
691 B
Python
Raw Normal View History

import random
import string
2023-11-19 15:52:48 +01:00
import sqlite3
def run_sqlite_command(*args):
2023-11-19 15:52:48 +01:00
"""Run a command against the database"""
con = sqlite3.connect("instance/partitioncloud.sqlite")
2023-11-19 15:52:48 +01:00
cur = con.cursor()
cur.execute(*args)
2023-11-19 15:52:48 +01:00
con.commit()
con.close()
def get_sqlite_data(*args):
"""Get data from the db"""
con = sqlite3.connect("instance/partitioncloud.sqlite")
cur = con.cursor()
data = cur.execute(*args)
2023-12-15 11:36:34 +01:00
new_data = list(data)
con.close()
return new_data
def new_uuid():
return ''.join([random.choice(string.ascii_uppercase + string.digits) for _ in range(6)])
def format_uuid(uuid):
"""Format old uuid4 format"""
2023-12-15 11:36:34 +01:00
return uuid.upper()[:6]