From 674dd8ea4e1ae6d6b95589e313661561506dd5dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C3=87a=C4=9Flayan?= Date: Sat, 20 Feb 2010 10:36:40 +0000 Subject: [PATCH] Feature: Add ability to use multiple tags for a source package You can now use 1 or more tags in source packages to download more than 1 tarballs in workDir. This is especially useful for packages like thunderbird where we're currently creating our own tarball to contain the source code + l10n files. This will also be useful on some binary drivers which has different tarballs for every architecture. pisi will automatically chdir into the directory which matches pkgname-pkgversion. If no directory matches this, you should provide WorkDir in actions.py as usually. If you'd like to apply your patches to every subarchive directory, you'll have to modify the patch levels and set WorkDir to "." (very very very rare case) Example: .. .. .. http://nvidia.com/driver_x86.tar.bz2 http://nvidia.com/driver_x86_64.tar.bz2 --- pisi-spec.rng | 4 +++- pisi/archive.py | 8 +++++--- pisi/operations/build.py | 23 ++++++++++------------- pisi/sourcearchive.py | 25 ++++++++++++++++++++++--- pisi/specfile.py | 2 +- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/pisi-spec.rng b/pisi-spec.rng index 4abecb62..25319fd9 100644 --- a/pisi-spec.rng +++ b/pisi-spec.rng @@ -48,7 +48,9 @@ - + + + diff --git a/pisi/archive.py b/pisi/archive.py index 847c5bfb..9f7cc234 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -47,10 +47,12 @@ class ArchiveBase(object): def unpack(self, target_dir, clean_dir = False): self.target_dir = target_dir # first we check if we need to clean-up our working env. - if os.path.exists(self.target_dir) and clean_dir: - util.clean_dir(self.target_dir) + if os.path.exists(self.target_dir): + if clean_dir: + util.clean_dir(self.target_dir) - os.makedirs(self.target_dir) + if not os.path.exists(self.target_dir): + os.makedirs(self.target_dir) class ArchiveBinary(ArchiveBase): diff --git a/pisi/operations/build.py b/pisi/operations/build.py index 2d510217..7e8ed768 100644 --- a/pisi/operations/build.py +++ b/pisi/operations/build.py @@ -192,7 +192,7 @@ class Builder: self.read_translations(self.specdir) - self.sourceArchive = pisi.sourcearchive.SourceArchive(self.spec, self.pkg_work_dir()) + self.sourceArchives = pisi.sourcearchive.SourceArchives(self.spec, self.pkg_work_dir()) self.set_environment_vars() @@ -259,8 +259,8 @@ class Builder: self.check_build_dependencies() self.fetch_component() - self.fetch_source_archive() - self.unpack_source_archive() + self.fetch_source_archives() + self.unpack_source_archives() # Grab AdditionalFiles self.copy_additional_source_files() @@ -392,15 +392,12 @@ class Builder: ctx.ui.info(_('Source is part of %s component') % comp.name) self.spec.source.partOf = comp.name - def fetch_source_archive(self): - ctx.ui.info(_("Fetching source from: %s") % self.spec.source.archive.uri) - self.sourceArchive.fetch() - ctx.ui.info(_("Source archive is stored: %s/%s") - %(ctx.config.archives_dir(), self.spec.source.archive.name)) + def fetch_source_archives(self): + self.sourceArchives.fetch() - def unpack_source_archive(self): - ctx.ui.info(_("Unpacking archive...")) - self.sourceArchive.unpack() + def unpack_source_archives(self): + ctx.ui.info(_("Unpacking archive(s)...")) + self.sourceArchives.unpack() # apply the patches and prepare a source directory for build. if self.apply_patches(): ctx.ui.info(_(" unpacked (%s)") % self.pkg_work_dir()) @@ -1094,12 +1091,12 @@ order = {"none": 0, def __buildState_fetch(pb): # fetch is the first state to run. pb.patch_exists() - pb.fetch_source_archive() + pb.fetch_source_archives() def __buildState_unpack(pb, last): if order[last] < order["fetch"]: __buildState_fetch(pb) - pb.unpack_source_archive() + pb.unpack_source_archives() def __buildState_setupaction(pb, last): if order[last] < order["unpack"]: diff --git a/pisi/sourcearchive.py b/pisi/sourcearchive.py index 394a26c0..793180ec 100644 --- a/pisi/sourcearchive.py +++ b/pisi/sourcearchive.py @@ -28,14 +28,29 @@ import pisi.mirrors class Error(pisi.Error): pass +class SourceArchives: + """This is a wrapper for supporting multiple SourceArchive objects.""" + def __init__(self, spec, pkg_work_dir): + self.sourceArchives = [SourceArchive(a, pkg_work_dir) for a in spec.source.archive] + + def fetch(self, interactive=True): + for archive in self.sourceArchives: + archive.fetch(interactive) + + def unpack(self, clean_dir=True): + self.sourceArchives[0].unpack(clean_dir) + for archive in self.sourceArchives[1:]: + archive.unpack(clean_dir=False) + + class SourceArchive: """source archive. this is a class responsible for fetching and unpacking a source archive""" - def __init__(self, spec, pkg_work_dir): - self.url = pisi.uri.URI(spec.source.archive.uri) + def __init__(self, archive, pkg_work_dir): + self.url = pisi.uri.URI(archive.uri) self.pkg_work_dir = pkg_work_dir self.archiveFile = os.path.join(ctx.config.archives_dir(), self.url.filename()) - self.archive = spec.source.archive + self.archive = archive def fetch(self, interactive=True): if not self.is_cached(interactive): @@ -45,6 +60,7 @@ class SourceArchive: self.progress = None try: + ctx.ui.info(_("Fetching source from: %s") % self.url.uri) if self.url.get_uri().startswith("mirrors://"): self.fetch_from_mirror() else: @@ -55,6 +71,9 @@ class SourceArchive: else: raise + ctx.ui.info(_("Source archive is stored: %s/%s") + % (ctx.config.archives_dir(), self.uri.filename())) + def fetch_from_fallback(self): archive = os.path.basename(self.url.get_uri()) src = os.path.join(ctx.config.values.build.fallback, archive) diff --git a/pisi/specfile.py b/pisi/specfile.py index edeffbac..711dbf0d 100644 --- a/pisi/specfile.py +++ b/pisi/specfile.py @@ -171,7 +171,7 @@ class Source: t_Summary = [autoxml.LocalText, autoxml.mandatory] t_Description = [autoxml.LocalText, autoxml.optional] t_Icon = [ autoxml.String, autoxml.optional] - t_Archive = [Archive, autoxml.mandatory ] + t_Archive = [ [Archive], autoxml.mandatory, "Archive" ] t_AdditionalFiles = [ [AdditionalFile], autoxml.optional] t_BuildDependencies = [ [pisi.dependency.Dependency], autoxml.optional] t_Patches = [ [Patch], autoxml.optional]