From cabf1fbeaad02316c99c34be28793ed9b58ea350 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 16 Oct 2011 10:45:30 +0200 Subject: [PATCH] Save capabilities in package metadata and database. --- po/pakfire.pot | 25 +++++++++++++++---------- python/pakfire/constants.py | 4 ++-- python/pakfire/errors.py | 3 +++ python/pakfire/filelist.py | 5 +++++ python/pakfire/packages/file.py | 10 ++++++++-- python/pakfire/packages/packager.py | 12 +++++++++--- python/pakfire/repository/database.py | 16 ++++++++++++---- 7 files changed, 54 insertions(+), 21 deletions(-) diff --git a/po/pakfire.pot b/po/pakfire.pot index 655af5e14..c13f9537c 100644 --- a/po/pakfire.pot +++ b/po/pakfire.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-10-15 16:48+0200\n" +"POT-Creation-Date: 2011-10-16 10:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -349,7 +349,7 @@ msgid "Do not verify build dependencies." msgstr "" #: ../python/pakfire/compress.py:133 -#: ../python/pakfire/packages/packager.py:495 +#: ../python/pakfire/packages/packager.py:501 #, python-format msgid "Compressing %s" msgstr "" @@ -362,22 +362,22 @@ msgstr "" msgid "An unhandled error occured." msgstr "" -#: ../python/pakfire/errors.py:51 +#: ../python/pakfire/errors.py:54 msgid "One or more dependencies could not been resolved." msgstr "" -#: ../python/pakfire/errors.py:66 +#: ../python/pakfire/errors.py:69 msgid "" "The requested action cannot be done on offline mode.\n" "Please connect your system to the network, remove --offline from the command " "line and try again." msgstr "" -#: ../python/pakfire/errors.py:78 +#: ../python/pakfire/errors.py:81 msgid "Running pakfire-build in a pakfire container?" msgstr "" -#: ../python/pakfire/errors.py:82 ../python/pakfire/transaction.py:381 +#: ../python/pakfire/errors.py:85 ../python/pakfire/transaction.py:381 msgid "Transaction test was not successful" msgstr "" @@ -497,7 +497,7 @@ msgstr "" msgid "Filename: %s" msgstr "" -#: ../python/pakfire/packages/file.py:259 +#: ../python/pakfire/packages/file.py:254 #, python-format msgid "File in archive is missing in file metadata: /%s. Skipping." msgstr "" @@ -521,11 +521,11 @@ msgid "Package version is undefined." msgstr "" #. Load progressbar. -#: ../python/pakfire/packages/packager.py:333 +#: ../python/pakfire/packages/packager.py:339 msgid "Packaging" msgstr "" -#: ../python/pakfire/packages/packager.py:621 +#: ../python/pakfire/packages/packager.py:627 #, python-format msgid "Building source package %s:" msgstr "" @@ -534,7 +534,12 @@ msgstr "" msgid "The format of the database is not supported by this version of pakfire." msgstr "" -#: ../python/pakfire/repository/database.py:217 +#: ../python/pakfire/repository/database.py:220 +#, python-format +msgid "Cannot use database with version greater than %s." +msgstr "" + +#: ../python/pakfire/repository/database.py:222 #, python-format msgid "Migrating database from format %s to %s." msgstr "" diff --git a/python/pakfire/constants.py b/python/pakfire/constants.py index a78a2a103..baa112dc9 100644 --- a/python/pakfire/constants.py +++ b/python/pakfire/constants.py @@ -57,9 +57,9 @@ METADATA_DOWNLOAD_PATH = "repodata" METADATA_DOWNLOAD_FILE = "repomd.json" METADATA_DATABASE_FILE = "packages.solv" -PACKAGE_FORMAT = 2 +PACKAGE_FORMAT = 3 # XXX implement this properly -PACKAGE_FORMATS_SUPPORTED = [0, 1, 2] +PACKAGE_FORMATS_SUPPORTED = [0, 1, 2, 3] PACKAGE_EXTENSION = "pfm" MAKEFILE_EXTENSION = "nm" diff --git a/python/pakfire/errors.py b/python/pakfire/errors.py index 9e8f0cc0e..29103a534 100644 --- a/python/pakfire/errors.py +++ b/python/pakfire/errors.py @@ -45,6 +45,9 @@ class BuildRootLocked(Error): class ConfigError(Error): pass +class DatabaseError(Error): + pass + class DependencyError(Error): exit_code = 4 diff --git a/python/pakfire/filelist.py b/python/pakfire/filelist.py index 05a06e0de..ef7ee35f4 100644 --- a/python/pakfire/filelist.py +++ b/python/pakfire/filelist.py @@ -67,6 +67,7 @@ class File(_File): self.user = 0 self.group = 0 self.mtime = 0 + self.capabilities = None def is_config(self): return self.config @@ -139,3 +140,7 @@ class FileDatabase(_File): @property def mtime(self): return self.row["mtime"] + + @property + def capabilities(self): + return self.row["capabilities"] diff --git a/python/pakfire/packages/file.py b/python/pakfire/packages/file.py index 0fb4abcb1..117be36d1 100644 --- a/python/pakfire/packages/file.py +++ b/python/pakfire/packages/file.py @@ -152,7 +152,7 @@ class FilePackage(Package): if not tarfile.is_tarfile(self.filename): raise FileError, "Given file is not of correct format: %s" % self.filename - assert self.format in PACKAGE_FORMATS_SUPPORTED + assert self.format in PACKAGE_FORMATS_SUPPORTED, self.format def get_format(self): a = self.open_archive() @@ -428,7 +428,10 @@ class FilePackage(Package): line = line.rstrip() line = line.split() - if len(line) <= 6: + # Check if fields do have the correct length. + if self.format >= 3 and len(line) <= 7: + continue + elif len(line) <= 6: continue name = line[0] @@ -471,6 +474,9 @@ class FilePackage(Package): if not line[7] == "-": file.hash1 = line[7] + if self.format >= 3 and not line[8] == "-": + file.capabilities = line[8] + else: name = line diff --git a/python/pakfire/packages/packager.py b/python/pakfire/packages/packager.py index 57273c092..e48018eed 100644 --- a/python/pakfire/packages/packager.py +++ b/python/pakfire/packages/packager.py @@ -158,11 +158,17 @@ class Packager(object): h.update(buf) mobj.close() - f.write(" %s\n" % h.hexdigest()) + f.write(" %s" % h.hexdigest()) + else: + f.write(" -") - # For other files, just finish the line. + caps = m.pax_headers.get("PAKFIRE.capabilities", None) + if caps: + f.write(" %s" % caps) else: - f.write(" -\n") + f.write(" -") + + f.write("\n") logging.info("") diff --git a/python/pakfire/repository/database.py b/python/pakfire/repository/database.py index 24d81541d..fb548497b 100644 --- a/python/pakfire/repository/database.py +++ b/python/pakfire/repository/database.py @@ -159,7 +159,8 @@ class DatabaseLocal(Database): user TEXT, `group` TEXT, hash1 TEXT, - mtime INTEGER + mtime INTEGER, + capabilities TEXT ); CREATE TABLE packages( @@ -214,6 +215,10 @@ class DatabaseLocal(Database): if self.format == DATABASE_FORMAT: return + # Check if database version is supported. + if self.format > DATABASE_FORMAT: + raise DatabaseError, _("Cannot use database with version greater than %s.") % DATABASE_FORMAT + logging.info(_("Migrating database from format %s to %s.") % (self.format, DATABASE_FORMAT)) # Get a database cursor. @@ -230,6 +235,9 @@ class DatabaseLocal(Database): c.execute("ALTER TABLE files ADD COLUMN `group` TEXT") c.execute("ALTER TABLE files ADD COLUMN `mtime` INTEGER") + if self.format < 3: + c.execute("ALTER TABLE files ADD COLUMN `capabilities` TEXT") + # In the end, we can easily update the version of the database. c.execute("UPDATE settings SET val = ? WHERE key = 'version'", (DATABASE_FORMAT,)) self.__format = DATABASE_FORMAT @@ -302,9 +310,9 @@ class DatabaseLocal(Database): pkg_id = c.lastrowid - c.executemany("INSERT INTO files(`name`, `pkg`, `size`, `config`, `type`, `hash1`, `mode`, `user`, `group`, `mtime`)" - " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - ((f.name, pkg_id, f.size, f.is_config(), f.type, f.hash1, f.mode, f.user, f.group, f.mtime) for f in pkg.filelist)) + c.executemany("INSERT INTO files(`name`, `pkg`, `size`, `config`, `type`, `hash1`, `mode`, `user`, `group`, `mtime`, `capabilities`)" + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + ((f.name, pkg_id, f.size, f.is_config(), f.type, f.hash1, f.mode, f.user, f.group, f.mtime, f.capabilities or "") for f in pkg.filelist)) except: raise -- 2.39.5