def main(): """ Use some docstring for comments! """ logger = Logger() signal.signal(signal.SIGINT, sig_int_handler) db_connect = None db = 'test.db' with sql.connect(db) as db_connect: # foreign keys are disabled by default for backwards compatibility db_connect.execute("""PRAGMA foreign_keys = ON;""") cursor = db_connect.cursor() cursor.execute("""PRAGMA foreign_keys;""") logger.log(Logger.INFO, "Creating table Sounds...") cursor.execute("""CREATE TABLE IF NOT EXISTS Sounds( sound_ID INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, filepath TEXT UNIQUE );""") logger.log(Logger.INFO, "Creating table Users...") cursor.execute("""CREATE TABLE IF NOT EXISTS Users( mac_address TEXT PRIMARY KEY NOT NULL, username TEXT, light_color TEXT, sound INTEGER REFERENCES Sounds(sound_ID) );""") cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='Sounds' OR name='Users';") created_tables = flatten(cursor.fetchall()) if len(created_tables) == 2: logger.log(Logger.INFO, "Tables successfully created.")
def get_latest_sdist(package_json): from itertools_recipes import flatten urls = flatten(package_json["releases"].values()) sdist_urls = [u for u in urls if u["packagetype"] == "sdist"] try: return sorted(sdist_urls, key=lambda u: u["upload_time"], reverse=True)[0]["url"] except: return None
def list_sounds(self): """ Provides a list of all sounds. :return: A list, containing the tuples (title, path). """ with sql.connect(self.db) as db_con: cursor = db_con.cursor() cursor.execute("SELECT title FROM Sounds") sound_list = flatten(cursor.fetchall()) return sound_list
def retrieve_users(self): """ Returns a list with all users. :return: A list containing all users. """ users = [] with sql.connect(self.db) as db_con: cursor = db_con.cursor() cursor.execute("SELECT mac_address FROM Users") mac_addresses = flatten(cursor.fetchall()) for mac_add in mac_addresses: user = self.get_user(mac_add) users.append(user) return users
def main(): """ Use some docstring for comments! """ logger = Logger() signal.signal(signal.SIGINT, sig_int_handler) db_connect = None db = 'test.db' with sql.connect(db) as db_connect: # foreign keys are disabled by default for backwards compatibility db_connect.execute("""PRAGMA foreign_keys = ON;""") cursor = db_connect.cursor() cursor.execute("""PRAGMA foreign_keys;""") logger.log(Logger.INFO, "Deleting table Users...") cursor.execute("""DROP TABLE IF EXISTS Users;""") logger.log(Logger.INFO, "Deleting table Sounds...") cursor.execute("""DROP TABLE IF EXISTS Sounds;""") cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='Sounds' OR name='Users';") deleted_tables = flatten(cursor.fetchall()) if len(deleted_tables) == 0: logger.log(Logger.INFO, "Tables successfully deleted.")