def __init__(self): """ Create database tables or manage update if needed """ if os.path.exists(self.DB_PATH): with SqlCursor(self) as sql: db_version = Lp().settings.get_value('db-version').get_int32() upgrade = DatabaseUpgrade(db_version, self) upgrade.do_db_upgrade() Lp().settings.set_value('db-version', GLib.Variant('i', upgrade.count())) else: try: if not os.path.exists(self.LOCAL_PATH): os.mkdir(self.LOCAL_PATH) # Create db schema with SqlCursor(self) as sql: sql.execute(self.create_albums) sql.execute(self.create_artists) sql.execute(self.create_genres) sql.execute(self.create_album_genres) sql.execute(self.create_album_artists) sql.execute(self.create_tracks) sql.execute(self.create_track_artists) sql.execute(self.create_track_genres) sql.commit() except Exception as e: print("Database::__init__(): %s" % e)
def __init__(self): """ Create database tables or manage update if needed """ # Create db directory if missing if not os.path.exists(self.LOCAL_PATH): try: os.mkdir(self.LOCAL_PATH) except: print("Can't create %s" % self.LOCAL_PATH) sql = self.get_cursor() db_version = Lp.settings.get_value('db-version').get_int32() upgrade = DatabaseUpgrade(db_version, sql) upgrade.do_db_upgrade() Lp.settings.set_value('db-version', GLib.Variant('i', upgrade.count())) # Create db schema try: sql.execute(self.create_albums) sql.execute(self.create_artists) sql.execute(self.create_genres) sql.execute(self.create_album_genres) sql.execute(self.create_tracks) sql.execute(self.create_track_artists) sql.execute(self.create_track_genres) sql.commit() except: pass
def upgrade(self): """ Upgrade database """ db_version = Lp().settings.get_value('db-version').get_int32() upgrade = DatabaseUpgrade(db_version, self) if os.path.exists(self.DB_PATH): upgrade.do_db_upgrade() Lp().settings.set_value('db-version', GLib.Variant('i', upgrade.count()))
def upgrade(self): """ Upgrade database """ db_version = Lp().settings.get_value('db-version').get_int32() upgrade = DatabaseUpgrade(db_version) f = Lio.File.new_for_path(self.DB_PATH) if f.query_exists(): upgrade.do_db_upgrade() Lp().settings.set_value('db-version', GLib.Variant('i', upgrade.count()))
def __init__(self): self._popularity_backup = {} # Create db directory if missing if not os.path.exists(self.LOCAL_PATH): try: os.mkdir(self.LOCAL_PATH) except: print("Can't create %s" % self.LOCAL_PATH) try: sql = self.get_cursor() except: exit(-1) db_version = Objects["settings"].get_value('db-version') upgrade = DatabaseUpgrade(sql, db_version) # Create db schema try: sql.execute(self.create_albums) sql.execute(self.create_artists) sql.execute(self.create_genres) sql.execute(self.create_tracks) sql.commit() Objects["settings"].set_value('db-version', GLib.Variant('i', upgrade.count())) # Upgrade db schema except: try: if db_version.get_int32() < upgrade.count(): Objects["settings"].set_value('db-version', GLib.Variant('i', upgrade.do_db_upgrade())) if upgrade.reset_needed(): self._set_popularities(sql) Objects["settings"].set_value('party-ids', GLib.Variant('ai', [])) sql.execute("DELETE FROM tracks") sql.execute("DELETE FROM albums") sql.execute("DELETE FROM artists") sql.execute("DELETE FROM genres") sql.commit() except Exception as e: print(e) pass sql.close()