From: Michael Tremer Date: Fri, 18 Mar 2011 15:48:45 +0000 (+0100) Subject: Unify packing code for source and binary packages. X-Git-Tag: 0.9.3~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d507be4d98d5c2b9fcdabf25d86521635e9285b3;p=pakfire.git Unify packing code for source and binary packages. --- diff --git a/pakfire/builder.py b/pakfire/builder.py index 1beeca011..eb6b363e5 100644 --- a/pakfire/builder.py +++ b/pakfire/builder.py @@ -585,7 +585,7 @@ class Builder(object): raise BuildError, "The build command failed." for pkg in reversed(self.packages): - packager = packages.Packager(self.pakfire, pkg, self) + packager = packages.BinaryPackager(self.pakfire, pkg, self) packager() def dist(self): diff --git a/pakfire/constants.py b/pakfire/constants.py index 824aad7e2..f32746ce2 100644 --- a/pakfire/constants.py +++ b/pakfire/constants.py @@ -61,6 +61,7 @@ BINARY_PACKAGE_META = SOURCE_PACKAGE_META = """\ ### %(name)s package VERSION="%(package_format)s" +TYPE="%(package_type)s" # Build information BUILD_DATE="%(build_date)s" diff --git a/pakfire/packages/make.py b/pakfire/packages/make.py index 5becbc00d..caeee63f8 100644 --- a/pakfire/packages/make.py +++ b/pakfire/packages/make.py @@ -42,6 +42,17 @@ class SourceDownloader(object): return filename +class MakeVirtualPackage(VirtualPackage): + """ + A simple package that always overwrites the file_patterns. + """ + @property + def file_patterns(self): + """ + All files that belong into a source package are located in /build. + """ + return ["/",] + class Makefile(Package): def __init__(self, pakfire, filename): Package.__init__(self, pakfire) @@ -91,46 +102,8 @@ class Makefile(Package): We assume that all requires files are in /build. """ - basedir = env.chrootPath("build") - - files = { - "data.img" : env.chrootPath("tmp/data.img"), - "signature" : env.chrootPath("tmp/signature"), - "info" : env.chrootPath("tmp/info"), - } - - # Package all files. - a = tarfile.open(files["data.img"], "w") - for dir, subdirs, _files in os.walk(basedir): - for file in _files: - file = os.path.join(dir, file) - - a.add(file, arcname=file[len(basedir):]) - a.close() - - # XXX add compression for the sources - - # Create an empty signature. - f = open(files["signature"], "w") - f.close() - - pkg = VirtualPackage(self.pakfire, env.make_info) - - # Save meta information. - f = open(files["info"], "w") - f.write(SOURCE_PACKAGE_META % { - "PKG_NAME" : pkg.name, - }) - f.close() - - result = env.chrootPath("result", "src", pkg.filename) - resultdir = os.path.dirname(result) - if not os.path.exists(resultdir): - os.makedirs(resultdir) - - f = tarfile.open(result, "w") - for arcname, name in files.items(): - f.add(name, arcname=arcname, recursive=False) + pkg = MakeVirtualPackage(self.pakfire, env.make_info) - f.close() + p = packager.SourcePackager(self.pakfire, pkg, env) + p() diff --git a/pakfire/packages/packager.py b/pakfire/packages/packager.py index 2de960e5e..168228188 100644 --- a/pakfire/packages/packager.py +++ b/pakfire/packages/packager.py @@ -22,8 +22,6 @@ from pakfire.i18n import _ from file import InnerTarFile -# XXX this is totally ugly and needs to be done right! - class Packager(object): ARCHIVE_FILES = ("info", "filelist", "data.img") @@ -34,12 +32,17 @@ class Packager(object): self.tarball = None + self.cleanup = True + # Store meta information self.info = { "package_format" : PACKAGE_FORMAT, - "package_type" : "binary", + "package_type" : self.type, "package_uuid" : uuid.uuid4(), "payload_comp" : None, + + "requires" : "", + "provides" : "", } self.info.update(self.pkg.info) self.info.update(self.pakfire.distro.info) @@ -64,24 +67,25 @@ class Packager(object): # Create the tarball and add all data to it. self.create_tarball() - e = self.env.do("/usr/lib/buildsystem-tools/dependency-tracker %s" % \ - self.tempdir[len(self.env.chrootPath()):], returnOutput=True, - env=self.pkg.env) + if self.type == "binary": + 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 + for line in e.splitlines(): + m = re.match(r"^(\w+)=(.*)$", line) + if m is None: + continue - key, val = m.groups() + key, val = m.groups() - if not key in ("requires", "provides"): - continue + if not key in ("requires", "provides"): + continue - val = val.strip("\"") - val = val.split() + val = val.strip("\"") + val = val.split() - self.info[key] = " ".join(sorted(val)) + self.info[key] = " ".join(sorted(val)) self.create_info() @@ -99,9 +103,16 @@ class Packager(object): tar.close() - def create_tarball(self, compress="xz"): + def create_tarball(self, compress=None): tar = InnerTarFile(self.archive_files["data.img"], mode="w") + prefix = self.env.buildroot + if self.type == "source": + prefix = "build" + + if not compress and self.type == "binary": + compress = "xz" + includes = [] excludes = [] @@ -118,7 +129,7 @@ class Packager(object): if pattern.startswith("/"): pattern = pattern[1:] - pattern = self.env.chrootPath(self.env.buildroot, pattern) + pattern = self.env.chrootPath(prefix, pattern) # Recognize the type of the pattern. Patterns could be a glob # pattern that is expanded here or just a directory which will @@ -152,7 +163,7 @@ class Packager(object): filelist = open(self.archive_files["filelist"], mode="w") for file_real in files: - file_tar = file_real[len(self.env.chrootPath(self.env.buildroot)) + 1:] + file_tar = file_real[len(self.env.chrootPath(prefix)) + 1:] file_tmp = os.path.join(self.tempdir, file_tar) if file_tar in ORPHAN_DIRECTORIES and not os.listdir(file_real): @@ -189,11 +200,12 @@ class Packager(object): shutil.copy2(file_real, file_tmp) # Unlink the file and remove empty directories. - if not os.path.isdir(file_real): - os.unlink(file_real) + if self.cleanup: + if not os.path.isdir(file_real): + os.unlink(file_real) - elif os.path.isdir(file_real) and not os.listdir(file_real): - os.rmdir(file_real) + elif os.path.isdir(file_real) and not os.listdir(file_real): + os.rmdir(file_real) # Dump all files that are in the archive. tar.list() @@ -220,3 +232,24 @@ class Packager(object): f = open(self.archive_files["info"], "w") f.write(BINARY_PACKAGE_META % self.info) f.close() + + @property + def type(self): + raise NotImplementedError + + +class BinaryPackager(Packager): + @property + def type(self): + return "binary" + + +class SourcePackager(Packager): + def __init__(self, *args, **kwargs): + Packager.__init__(self, *args, **kwargs) + + self.cleanup = False + + @property + def type(self): + return "source" diff --git a/pakfire/repository/local.py b/pakfire/repository/local.py index bd2f44bc1..588e65b52 100644 --- a/pakfire/repository/local.py +++ b/pakfire/repository/local.py @@ -67,10 +67,16 @@ class LocalRepository(RepositoryFactory): # If package in the repo is equivalent to the given one, we can # skip any further processing. - if pkg == pkg_exists: + if pkg.hash1 == pkg_exists.hash1: logging.debug("The package does already exist in this repo: %s" % pkg.friendly_name) copy = False + else: + logging.warning("The package is going to be replaced: %s -> %s" % (pkg_exists, pkg)) + os.unlink(repo_filename) + + del pkg_exists + if copy: logging.debug("Copying package '%s' to repository." % pkg.friendly_name) repo_dirname = os.path.dirname(repo_filename)