From: Michael Tremer Date: Fri, 18 Mar 2011 14:32:42 +0000 (+0100) Subject: Simplify the package creation process and add payload checksum. X-Git-Tag: 0.9.3~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c617c20ea81306242c24bfde423be2ae5c7e4f9;p=pakfire.git Simplify the package creation process and add payload checksum. --- diff --git a/pakfire/constants.py b/pakfire/constants.py index b77ac015e..824aad7e2 100644 --- a/pakfire/constants.py +++ b/pakfire/constants.py @@ -47,13 +47,17 @@ SOURCE_CACHE_DIR = os.path.join(CACHE_DIR, "sources") TIME_10M = 10 TIME_24H = 60*24 -SOURCE_PACKAGE_META = """\ - -PKG_NAME="%(PKG_NAME)s" - -""" - -BINARY_PACKAGE_META = """\ +ORPHAN_DIRECTORIES = [ + "lib", "lib64", "usr/lib", "usr/lib64", "libexec", "usr/libexec", + "bin", "sbin", "usr/bin", "usr/sbin", "usr/include", "usr/share", + "usr/share/man", "usr/share/man/man0", "usr/share/man/man1", + "usr/share/man/man2", "usr/share/man/man3", "usr/share/man/man4", + "usr/share/man/man5", "usr/share/man/man6", "usr/share/man/man7", + "usr/share/man/man8", "usr/share/man/man9", "usr/lib/pkgconfig", +] +ORPHAN_DIRECTORIES.sort(cmp=lambda x,y: cmp(len(x), len(y)), reverse=True) + +BINARY_PACKAGE_META = SOURCE_PACKAGE_META = """\ ### %(name)s package VERSION="%(package_format)s" @@ -91,5 +95,6 @@ PKG_REQUIRES="%(requires)s" PKG_PROVIDES="%(provides)s" PKG_PAYLOAD_COMP="%(payload_comp)s" +PKG_PAYLOAD_HASH1="%(payload_hash1)s" """ diff --git a/pakfire/packages/packager.py b/pakfire/packages/packager.py index 12fb5b23c..2de960e5e 100644 --- a/pakfire/packages/packager.py +++ b/pakfire/packages/packager.py @@ -5,6 +5,7 @@ import logging import lzma import os import progressbar +import re import shutil import sys import tarfile @@ -14,6 +15,7 @@ import xattr import zlib import pakfire.compress +import util from pakfire.constants import * from pakfire.i18n import _ @@ -62,13 +64,24 @@ class Packager(object): # Create the tarball and add all data to it. self.create_tarball() - chroot_tempdir = self.tempdir[len(self.env.chrootPath()):] - self.info.update({ - "requires" : self.env.do("/usr/lib/buildsystem-tools/dependency-tracker requires %s" % chroot_tempdir, - returnOutput=True, env=self.pkg.env).strip(), - "provides" : self.env.do("/usr/lib/buildsystem-tools/dependency-tracker provides %s" % chroot_tempdir, - returnOutput=True, env=self.pkg.env).strip(), - }) + e = self.env.do("/usr/lib/buildsystem-tools/dependency-tracker %s" % \ + self.tempdir[len(self.env.chrootPath()):], returnOutput=True, + env=self.pkg.env) + + for line in e.splitlines(): + m = re.match(r"^(\w+)=(.*)$", line) + if m is None: + continue + + key, val = m.groups() + + if not key in ("requires", "provides"): + continue + + val = val.strip("\"") + val = val.split() + + self.info[key] = " ".join(sorted(val)) self.create_info() @@ -125,9 +138,6 @@ class Packager(object): else: files.append(pattern) - else: - logging.warning("Unrecognized pattern type: %s" % pattern) - files = [] for file in includes: # Skip if file is already in the file set or @@ -145,6 +155,11 @@ class Packager(object): file_tar = file_real[len(self.env.chrootPath(self.env.buildroot)) + 1:] file_tmp = os.path.join(self.tempdir, file_tar) + if file_tar in ORPHAN_DIRECTORIES and not os.listdir(file_real): + logging.debug("Found an orphaned directory: %s" % file_tar) + os.unlink(file_real) + continue + tar.add(file_real, arcname=file_tar) # Record the packaged file to the filelist. @@ -198,6 +213,9 @@ class Packager(object): pakfire.compress.compress(self.archive_files["data.img"], algo=compress, progress=True) + # Calc hashsum of the payload of the package. + self.info["payload_hash1"] = util.calc_hash1(self.archive_files["data.img"]) + def create_info(self): f = open(self.archive_files["info"], "w") f.write(BINARY_PACKAGE_META % self.info)