Beispiel #1
0
    def Init(self, reset, convert):
        self.logger.info(
            'Using SQLite version {}, python library sqlite3 version {}',
            sqlite3.sqlite_version, sqlite3.version)
        if not mvutils.dir_exists(self.settings.datapath):
            os.mkdir(self.settings.datapath)

        # remove old versions
        mvutils.file_remove(
            os.path.join(self.settings.datapath, 'filmliste-v1.db'))

        if reset == True or not mvutils.file_exists(self.dbfile):
            self.logger.info(
                '===== RESET: Database will be deleted and regenerated =====')
            mvutils.file_remove(self.dbfile)
            self.conn = sqlite3.connect(self.dbfile, timeout=60)
            self._handle_database_initialization()
        else:
            try:
                self.conn = sqlite3.connect(self.dbfile, timeout=60)
            except sqlite3.DatabaseError as err:
                self.logger.error(
                    'Error while opening database: {}. trying to fully reset the Database...',
                    err)
                return self.Init(reset=True, convert=convert)

        self.conn.execute(
            'pragma journal_mode=off')  # 3x speed-up, check mode 'WAL'
        self.conn.execute('pragma synchronous=off'
                          )  # that is a bit dangerous :-) but faaaast
        self.conn.create_function('UNIX_TIMESTAMP', 0, UNIX_TIMESTAMP)
        self.conn.create_aggregate('GROUP_CONCAT', 1, GROUP_CONCAT)
        return True
Beispiel #2
0
    def init(self, reset=False, convert=False):
        """
        Startup of the database system

        Args:
            reset(bool, optional): if `True` the database
                will be cleaned up and recreated. Default
                is `False`

            convert(bool, optional): if `True` the database
                will be converted in case it is older than
                the supported version. If `False` a UI message
                will be displayed to the user informing that
                the database will be converted. Default is
                `False`
        """
        self.logger.info(
            'Using SQLite version {}, python library sqlite3 version {}',
            sqlite3.sqlite_version, sqlite3.version)
        if not mvutils.dir_exists(self.settings.datapath):
            os.mkdir(self.settings.datapath)

        # remove old versions
        mvutils.file_remove(
            os.path.join(self.settings.datapath, 'filmliste-v1.db'))

        if reset is True or not mvutils.file_exists(self.dbfile):
            self.logger.info(
                '===== RESET: Database will be deleted and regenerated =====')
            self.exit()
            mvutils.file_remove(self.dbfile)
            if self._handle_update_substitution():
                self.conn = sqlite3.connect(self.dbfile, timeout=60)
            else:
                self.conn = sqlite3.connect(self.dbfile, timeout=60)
                self._handle_database_initialization()
        else:
            self._handle_update_substitution()
            try:
                self.conn = sqlite3.connect(self.dbfile, timeout=60)
            except sqlite3.DatabaseError as err:
                self.logger.error(
                    'Error while opening database: {}. trying to fully reset the Database...',
                    err)
                return self.init(reset=True, convert=convert)

        # 3x speed-up, check mode 'WAL'
        self.conn.execute('pragma journal_mode=off')
        # that is a bit dangerous :-) but faaaast
        self.conn.execute('pragma synchronous=off')
        self.conn.create_function('UNIX_TIMESTAMP', 0, get_unix_timestamp)
        self.conn.create_aggregate('GROUP_CONCAT', 1, GroupConcatClass)
        return True
Beispiel #3
0
	def Init( self, reset = False ):
		self.logger.info( 'Using SQLite version {}, python library sqlite3 version {}', sqlite3.sqlite_version, sqlite3.version )
		if not mvutils.dir_exists( self.settings.datapath ):
			os.mkdir( self.settings.datapath )
		if reset == True or not mvutils.file_exists( self.dbfile ):
			self.logger.info( '===== RESET: Database will be deleted and regenerated =====' )
			self._file_remove( self.dbfile )
			self.conn = sqlite3.connect( self.dbfile, timeout = 60 )
			self._handle_database_initialization()
		else:
			try:
				self.conn = sqlite3.connect( self.dbfile, timeout = 60 )
			except sqlite3.DatabaseError as err:
				self.logger.error( 'Error while opening database: {}. trying to fully reset the Database...', err )
				self.Init( reset = True )

		self.conn.execute( 'pragma journal_mode=off' )	# 3x speed-up, check mode 'WAL'
		self.conn.execute( 'pragma synchronous=off' )	# that is a bit dangerous :-) but faaaast

		self.conn.create_function( 'UNIX_TIMESTAMP', 0, UNIX_TIMESTAMP )
		self.conn.create_aggregate( 'GROUP_CONCAT', 1, GROUP_CONCAT )
Beispiel #4
0
    def init(self, reset=False, convert=False, failedCount=0):
        """
        Startup of the database system

        Args:
            reset(bool, optional): if `True` the database
                will be cleaned up and recreated. Default
                is `False`

            convert(bool, optional): if `True` the database
                will be converted in case it is older than
                the supported version. If `False` a UI message
                will be displayed to the user informing that
                the database will be converted. Default is
                `False`
        """
        self.logger.info(
            'Using SQLite version {}, python library sqlite3 version {}',
            sqlite3.sqlite_version, sqlite3.version)
        if not mvutils.dir_exists(self.settings.datapath):
            os.mkdir(self.settings.datapath)

        # remove old versions
        mvutils.file_remove(
            os.path.join(self.settings.datapath, 'filmliste-v1.db'))

        if reset is True or not mvutils.file_exists(self.dbfile):
            self.logger.info(
                '===== RESET: Database will be deleted and regenerated =====')
            self.exit()
            mvutils.file_remove(self.dbfile)
            if self._handle_update_substitution():
                self.conn = sqlite3.connect(self.dbfile, timeout=60)
            else:
                self.conn = sqlite3.connect(self.dbfile, timeout=60)
                self._handle_database_initialization()
        else:
            try:
                if self._handle_update_substitution():
                    self._handle_not_update_to_date_dbfile()
                self.conn = sqlite3.connect(self.dbfile, timeout=60)
            except sqlite3.DatabaseError as err:
                self.logger.error(
                    'Error while opening database: {}. trying to fully reset the Database...',
                    err)
                return self.init(reset=True, convert=convert)
        try:

            # 3x speed-up, check mode 'WAL'
            self.conn.execute('pragma journal_mode=off')
            # check if DB is ready or broken
            cursor = self.conn.cursor()
            cursor.execute('SELECT * FROM `status` LIMIT 1')
            rs = cursor.fetchall()
            ##
            self.logger.info('Current DB Status Last modified {} ({})',
                             time.ctime(rs[0][0]), rs[0][0])
            self.logger.info('Current DB Status Last lastupdate {} ({})',
                             time.ctime(rs[0][2]), rs[0][2])
            self.logger.info('Current DB Status Last filmupdate {} ({})',
                             time.ctime(rs[0][3]), rs[0][3])
            self.logger.info('Current DB Status Last fullupdate {}', rs[0][4])
            ##
            cursor.close()
        except sqlite3.DatabaseError as err:
            failedCount += 1
            if (failedCount > 3):
                self.logger.error(
                    'Failed to restore database, please uninstall plugin, delete user profile and reinstall'
                )
                raise err
            self.logger.error(
                'Error on first query: {}. trying to fully reset the Database...trying {} times',
                err, failedCount)
            return self.init(reset=True,
                             convert=convert,
                             failedCount=failedCount)
        # that is a bit dangerous :-) but faaaast
        self.conn.execute('pragma synchronous=off')
        self.conn.create_function('UNIX_TIMESTAMP', 0, get_unix_timestamp)
        self.conn.create_aggregate('GROUP_CONCAT', 1, GroupConcatClass)
        return True