From: Michael Tremer Date: Sun, 28 Aug 2011 19:53:27 +0000 (+0200) Subject: Misc. fixes on extraction and packaging. X-Git-Tag: 0.9.9~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=75bb74a778a3bf911453ced4b3c7b618cc3fa7a2;p=pakfire.git Misc. fixes on extraction and packaging. --- diff --git a/pakfire/base.py b/pakfire/base.py index 9257f4844..9ba126bc7 100644 --- a/pakfire/base.py +++ b/pakfire/base.py @@ -290,6 +290,7 @@ class Pakfire(object): finally: # Remove the temporary copy of the repository we have created earlier. repo.remove() + self.repos.rem_repo(repo) def update(self, pkgs, check=False): """ @@ -410,7 +411,7 @@ class Pakfire(object): return sorted(pkgs) @staticmethod - def build(pkg, resultdirs=None, shell=False, **kwargs): + def build(pkg, resultdirs=None, shell=False, install_test=True, **kwargs): if not resultdirs: resultdirs = [] @@ -423,8 +424,7 @@ class Pakfire(object): try: b.prepare() b.extract() - b.build() - b.install_test() + b.build(install_test=install_test) # Copy-out all resultfiles for resultdir in resultdirs: diff --git a/pakfire/builder.py b/pakfire/builder.py index 499ec9276..1cc433caa 100644 --- a/pakfire/builder.py +++ b/pakfire/builder.py @@ -580,55 +580,15 @@ class BuildEnviron(object): return ret - def build(self): + def build(self, install_test=True): assert self.pkg - # Create icecream toolchain. - self.create_icecream_toolchain() - - # Create the build script and build command. - build_script = self.create_buildscript() - build_cmd = "/bin/sh -e -x %s" % build_script - - try: - self.do(build_cmd, logger=self.log) - - except Error: - raise BuildError, "The build command failed." - - # XXX clean up that mess after this line - - # Create a temporary repository where we put in the just built packages. - repo = repository.RepositoryDir(self.pakfire, "build-%s" % self.build_id, - "", self.chrootPath("result"), type="binary") - self.pakfire.repos.add_repo(repo) - - # Make all these little package from the build environment. - for pkg in reversed(self.pkg.packages): - packager = packages.packager.BinaryPackager(self.pakfire, pkg, self) - packager.run([repo.path,]) - self.log.info("") - - # Update repository metadata. - repo.update(force=True) - - self.log.info(_("Dumping created packages")) - - for line in repo.dump(long=True, filelist=True).splitlines(): - self.log.info(" %s" % line) - self.log.info("") - - self.pakfire.repos.rem_repo(repo) - - return repo - - def build(self): pkgfile = os.path.join("/build", os.path.basename(self.pkg.filename)) resultdir = self.chrootPath("/result") # Create the build command, that is executed in the chroot. build_command = ["pakfire-build2", "--offline", "build", pkgfile, - "--nodeps",] + "--nodeps", "--resultdir=/result",] try: self.do(" ".join(build_command), logger=self.log) @@ -636,6 +596,10 @@ class BuildEnviron(object): except Error: raise BuildError, _("The build command failed. See logfile for details.") + # Perform install test. + if install_test: + self.install_test() + # Copy the final packages and stuff. # XXX TODO resultdir @@ -779,7 +743,7 @@ class Builder2(object): logging.info(_("Creating packages:")) for pkg in reversed(self.pkg.packages): packager = packages.packager.BinaryPackager(self.pakfire, pkg, self.buildroot) - packager.run([self.resultdir,]) + packager.run(self.resultdir) logging.info("") def build_stage(self, stage): @@ -788,11 +752,14 @@ class Builder2(object): # Execute the buildscript of this stage. logging.info(_("Running stage %s:") % stage) - self.do(buildscript, shell=False) - # Remove the buildscript. - if os.path.exists(buildscript): - os.unlink(buildscript) + try: + self.do(buildscript, shell=False) + + finally: + # Remove the buildscript. + if os.path.exists(buildscript): + os.unlink(buildscript) def cleanup(self): if os.path.exists(self.buildroot): diff --git a/pakfire/packages/file.py b/pakfire/packages/file.py index c4cdacd88..fff1eb0a0 100644 --- a/pakfire/packages/file.py +++ b/pakfire/packages/file.py @@ -29,6 +29,7 @@ import xattr import pakfire.util as util import pakfire.compress as compress from pakfire.constants import * +from pakfire.i18n import _ from base import Package from lexer import FileLexer @@ -91,13 +92,22 @@ class InnerTarFile(tarfile.TarFile): self.addfile(tarinfo) def extract(self, member, path=""): + target = os.path.join(path, member.name) + + # Remove symlink targets, because tarfile cannot replace them. + if member.issym() and os.path.exists(target): + print "unlinking", target + os.unlink(target) + # Extract file the normal way... - tarfile.TarFile.extract(self, member, path) + try: + tarfile.TarFile.extract(self, member, path) + except OSError, e: + logging.warning(_("Could not extract file: /%s - %s") \ + % (member.name, e)) # ...and then apply the extended attributes. if member.pax_headers: - target = os.path.join(path, member.name) - for attr, val in member.pax_headers.items(): # Skip all attrs that are not supported (e.g. selinux). if not attr in self.SUPPORTED_XATTRS: diff --git a/pakfire/packages/packager.py b/pakfire/packages/packager.py index 3f33facc8..eeb44684d 100644 --- a/pakfire/packages/packager.py +++ b/pakfire/packages/packager.py @@ -267,10 +267,15 @@ class BinaryPackager(Packager): # Recognize the type of the pattern. Patterns could be a glob # pattern that is expanded here or just a directory which will # be included recursively. - if "*" in pattern or "?" in pattern: - patterns += glob.glob(pattern) + if "*" in pattern or "?" in pattern or ("[" in pattern and "]" in pattern): + _patterns = glob.glob(pattern) + else: + _patterns = [pattern,] + + for pattern in _patterns: + if not os.path.exists(pattern): + continue - elif os.path.exists(pattern): # Add directories recursively... if os.path.isdir(pattern): # Add directory itself. @@ -475,9 +480,7 @@ class BinaryPackager(Packager): def compress_datafile(self, datafile, algo="xz"): pass - def run(self, resultdirs=[]): - assert resultdirs - + def run(self, resultdir): # Add all files to this package. datafile = self.create_datafile() @@ -506,28 +509,18 @@ class BinaryPackager(Packager): tempfile = self.mktemp() self.save(tempfile) - for resultdir in resultdirs: - # XXX sometimes, there has been a None in resultdirs - if not resultdir: - continue + # Add architecture information to path. + resultdir = "%s/%s" % (resultdir, self.pkg.arch) - resultdir = "%s/%s" % (resultdir, self.pkg.arch) - - if not os.path.exists(resultdir): - os.makedirs(resultdir) - - resultfile = os.path.join(resultdir, self.pkg.package_filename) - logging.info("Saving package to %s" % resultfile) - try: - os.link(tempfile, resultfile) - except OSError: - shutil.copy2(tempfile, resultfile) + if not os.path.exists(resultdir): + os.makedirs(resultdir) - ## Dump package information. - #pkg = BinaryPackage(self.pakfire, self.pakfire.repos.dummy, tempfile) - #for line in pkg.dump(long=True).splitlines(): - # logging.info(line) - #logging.info("") + resultfile = os.path.join(resultdir, self.pkg.package_filename) + logging.info("Saving package to %s" % resultfile) + try: + os.link(tempfile, resultfile) + except OSError: + shutil.copy2(tempfile, resultfile) class SourcePackager(Packager): diff --git a/po/pakfire.pot b/po/pakfire.pot index 349ac7171..9d9b148e4 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-08-28 18:13+0200\n" +"POT-Creation-Date: 2011-08-28 21:19+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -61,7 +61,7 @@ msgid "Downgrading" msgstr "" #: ../pakfire/base.py:199 ../pakfire/base.py:229 ../pakfire/base.py:275 -#: ../pakfire/base.py:315 ../pakfire/base.py:348 +#: ../pakfire/base.py:316 ../pakfire/base.py:349 msgid "Nothing to do" msgstr "" @@ -86,22 +86,18 @@ msgstr "" msgid "Extracting" msgstr "" -#: ../pakfire/builder.py:615 -msgid "Dumping created packages" -msgstr "" - -#: ../pakfire/builder.py:637 +#: ../pakfire/builder.py:599 msgid "The build command failed. See logfile for details." msgstr "" #. Package the result. #. Make all these little package from the build environment. -#: ../pakfire/builder.py:779 +#: ../pakfire/builder.py:745 msgid "Creating packages:" msgstr "" #. Execute the buildscript of this stage. -#: ../pakfire/builder.py:790 +#: ../pakfire/builder.py:756 #, python-format msgid "Running stage %s:" msgstr "" @@ -445,7 +441,12 @@ msgstr "" msgid "Not set" msgstr "" -#: ../pakfire/packages/file.py:146 +#: ../pakfire/packages/file.py:106 +#, python-format +msgid "Could not extract file: /%s - %s" +msgstr "" + +#: ../pakfire/packages/file.py:156 #, python-format msgid "Filename: %s" msgstr "" @@ -459,11 +460,11 @@ msgid "Package version is undefined." msgstr "" #. Load progressbar. -#: ../pakfire/packages/packager.py:306 +#: ../pakfire/packages/packager.py:309 msgid "Packaging" msgstr "" -#: ../pakfire/packages/packager.py:599 +#: ../pakfire/packages/packager.py:590 #, python-format msgid "Building source package %s:" msgstr ""