Ejemplo n.º 1
0
    def execute(self,
                sqlquery,
                args,
                repeat=False):  # type: (str, tuple, bool) -> None
        self.cur.execute("BEGIN")
        try:
            self.cur.execute(sqlquery, args)

        # Handle database errors
        except sqlite3.DatabaseError as e:
            # Check if database is currupted
            if not repeat and os.path.exists(self.filepath) and \
                    (str(e).find("file is encrypted") > -1 or str(e).find("not a database") > -1):
                Script.log("Deleting broken database file: %s",
                           (self.filepath, ),
                           lvl=Script.DEBUG)
                self.close()
                os.remove(self.filepath)
                self._connect()
                self.execute(sqlquery, args, repeat=True)
            else:
                raise e

        # Just roll back database on error and raise again
        except Exception as e:
            self.db.rollback()
            raise e
        else:
            self.db.commit()
Ejemplo n.º 2
0
def import_needed_module():
    """Import needed module according to the Kodi base URL and query string

    TODO: Remove this import 'hack' when CodeQuick 0.9.11 will be released

    """

    modules_to_import = [get_module_in_url(sys.argv[0])]
    if 'codequick/search' in sys.argv[0]:
        modules_to_import.append(get_module_in_query(sys.argv[2]))
    for module_to_import in modules_to_import:
        if module_to_import == '':
            # No additionnal module to load
            continue

        # Need to load additional module
        try:
            Script.log(
                '[import_needed_module] Import module {} on the fly'.format(
                    module_to_import),
                lvl=Script.INFO)
            importlib.import_module(module_to_import)
        except Exception:
            Script.log(
                '[import_needed_module] Failed to import module {} on the fly'.
                format(module_to_import),
                lvl=Script.WARNING)