]> git.ipfire.org Git - pakfire.git/commitdiff
Unify packing code for source and binary packages.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Mar 2011 15:48:45 +0000 (16:48 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Mar 2011 15:48:45 +0000 (16:48 +0100)
pakfire/builder.py
pakfire/constants.py
pakfire/packages/make.py
pakfire/packages/packager.py
pakfire/repository/local.py

index 1beeca011651f62d7c3c87437c1b3be2977fb4ed..eb6b363e56fc077ddfa7b13fdb16773cbfdc04c7 100644 (file)
@@ -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):
index 824aad7e26f48683b3c13f8634bc282aa4d65abe..f32746ce26e67827c8c1110ba64dfb4002ce9f7a 100644 (file)
@@ -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"
index 5becbc00d314d0c8d0e18f494346c2672bd8661a..caeee63f862177712459ce61f9618faf15ec5651 100644 (file)
@@ -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()
 
index 2de960e5ee42cd32fb0568286cf6284eab620a38..1682281883a1649aaa963212906c41de15b2be51 100644 (file)
@@ -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"
index bd2f44bc153a54973ea59e3e3cdfef62dcca0879..588e65b52ce666f0ffe9078fe47f77c7ab15d9d1 100644 (file)
@@ -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)