Example #1
0
 def __init__(self):
     """
         Create database tables or manage update if needed
     """
     f = Lio.File.new_for_path(self.DB_PATH)
     if not f.query_exists():
         db_version = Lp().settings.get_value('db-version').get_int32()
         upgrade = DatabaseUpgrade(db_version)
         try:
             d = Lio.File.new_for_path(self.__LOCAL_PATH)
             if not d.query_exists():
                 d.make_directory_with_parents()
             # 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.execute(self.__create_album_artists_idx)
                 sql.execute(self.__create_track_artists_idx)
                 sql.execute(self.__create_album_genres_idx)
                 sql.execute(self.__create_track_genres_idx)
                 sql.commit()
                 Lp().settings.set_value('db-version',
                                         GLib.Variant('i', upgrade.count()))
         except Exception as e:
             print("Database::__init__(): %s" % e)
Example #2
0
 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)
Example #3
0
    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
Example #4
0
 def __init__(self):
     """
         Create database tables or manage update if needed
     """
     f = Lio.File.new_for_path(self.DB_PATH)
     if not f.query_exists():
         db_version = Lp().settings.get_value('db-version').get_int32()
         upgrade = DatabaseUpgrade(db_version)
         try:
             d = Lio.File.new_for_path(self.__LOCAL_PATH)
             if not d.query_exists():
                 d.make_directory_with_parents()
             # 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.execute(self.__create_album_artists_idx)
                 sql.execute(self.__create_track_artists_idx)
                 sql.execute(self.__create_album_genres_idx)
                 sql.execute(self.__create_track_genres_idx)
                 sql.commit()
                 Lp().settings.set_value('db-version',
                                         GLib.Variant('i', upgrade.count()))
         except Exception as e:
             print("Database::__init__(): %s" % e)
Example #5
0
 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()))
Example #6
0
 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()))
Example #7
0
 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()))
Example #8
0
	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()