Exemplo n.º 1
0
    def loadCache(self, filename):
        """Load cache from filename, check if it is valid and that dbversion
        matches the required dbversion"""
        db = sqlite3.connect(filename)
        db.row_factory = sqlite3.Row
        db.text_factory = str
        cur = db.cursor()
        cur.execute("SELECT * FROM db_info")
        info = cur.fetchone()
        # If info is not in there this is an incompelete cache file
        # (this could happen when the user hits ctrl-c or kills yum
        # when the cache is being generated or updated)
        if not info:
            raise sqlite3.DatabaseError, "Incomplete database cache file"

        # Now check the database version
        if info['dbversion'] not in supported_dbversions:
            log.info2(
                "Cache file is version %s, we need %s, will "
                "regenerate.\n", info['dbversion'], dbversion)
            raise sqlite3.DatabaseError, "Older version of yum sqlite: %s" % info[
                'dbversion']

        # This appears to be a valid database, return checksum value and
        # database object
        return (info['checksum'], db)
Exemplo n.º 2
0
    def create(self, filename):
        """Create an initial database"""

        # If it exists, remove it as we were asked to create a new one
        if os.path.exists(filename):
            try:
                os.unlink(filename)
            except OSError:
                pass

        # Try to create the databse in filename, or use in memory when
        # this fails
        try:
            f = open(filename, 'w')
            db = sqlite3.connect(filename)
        except IOError:
            log.warning("Could not create sqlite cache file, using in memory "
                        "cache instead")
            db = sqlite3.connect(":memory:")
        db.row_factory = sqlite3.Row
        db.text_factory = str
        return db
Exemplo n.º 3
0
    def create(self, filename):
        """Create an initial database"""

        # If it exists, remove it as we were asked to create a new one
        if os.path.exists(filename):
            try:
                os.unlink(filename)
            except OSError:
                pass

        # Try to create the databse in filename, or use in memory when
        # this fails
        try:
            f = open(filename, 'w')
            db = sqlite3.connect(filename)
        except IOError:
            log.warning("Could not create sqlite cache file, using in memory "
                        "cache instead")
            db = sqlite3.connect(":memory:")
        db.row_factory = sqlite3.Row
        db.text_factory = str
        return db
Exemplo n.º 4
0
    def loadCache(self, filename):
        """Load cache from filename, check if it is valid and that dbversion
        matches the required dbversion"""
        db = sqlite3.connect(filename)
        db.row_factory = sqlite3.Row
        db.text_factory = str
        cur = db.cursor()
        cur.execute("SELECT * FROM db_info")
        info = cur.fetchone()
        # If info is not in there this is an incompelete cache file
        # (this could happen when the user hits ctrl-c or kills yum
        # when the cache is being generated or updated)
        if not info:
            raise sqlite3.DatabaseError, "Incomplete database cache file"

        # Now check the database version
        if info['dbversion'] not in supported_dbversions:
            log.info2("Cache file is version %s, we need %s, will "
                      "regenerate.\n", info['dbversion'], dbversion)
            raise sqlite3.DatabaseError, "Older version of yum sqlite: %s" % info['dbversion']

        # This appears to be a valid database, return checksum value and
        # database object
        return (info['checksum'], db)