From e4456fd18caa86f2a7d7a21df4e6a78efafbff77 Mon Sep 17 00:00:00 2001 From: "Yaakov M. Nemoy" Date: Fri, 16 Jan 2009 18:26:38 -0500 Subject: Adds sourceball fetching from packagesources to package --- base/util.py | 6 +++++- modules/darcs.py | 10 ---------- modules/directory.py | 1 + modules/package.py | 44 +++++++++++++++++++++++++++++++++++++++++++- modules/packagesource.py | 4 ++-- modules/sourceball.py | 7 +++++++ 6 files changed, 58 insertions(+), 14 deletions(-) diff --git a/base/util.py b/base/util.py index e192b94..5f71534 100644 --- a/base/util.py +++ b/base/util.py @@ -85,6 +85,10 @@ def copytree(src, dst): cpthree(src, dst) return dst +def remove_all(i, l): + while i in l: + l.remove(i) + def one(l, f): for x in l: if f(x): @@ -105,4 +109,4 @@ def flatten(l): return acc __all__ = ['pwd', 'copy', 'with_sudo', 'with_su', 'symlink', 'move', - 'log_file', 'one'] + 'log_file', 'one', 'remove_all', 'flatten'] diff --git a/modules/darcs.py b/modules/darcs.py index b6a4d96..4c150b0 100644 --- a/modules/darcs.py +++ b/modules/darcs.py @@ -69,16 +69,6 @@ class Darcs(RevisionControl): log.info('darcs get %s %s, please wait....' % (src, tgt)) p.communicate() -# def checkout(self, tgt, url, *args): -# '''checks out source from an upstream url - -# the difference between this and get is that it reflects an initial pull -# idiom found in other VCSes. It also handles setting vc_url and the -# canonical name, based on tgt -# ''' -# self.cfg['vc_url'] = url -# self.get(url, tgt, *args) - @property def vc_url(self): '''the url where the source was fetched from originally diff --git a/modules/directory.py b/modules/directory.py index 31c864c..2692f06 100644 --- a/modules/directory.py +++ b/modules/directory.py @@ -26,6 +26,7 @@ from os import makedirs, getcwd, listdir from os.path import abspath, join, split, splitext, basename, exists, dirname from base.base import log +from base.dirfactory import DirFactory from base.module import Module from base.util import pwd, copytree diff --git a/modules/package.py b/modules/package.py index 8fdeb93..bf1e3ec 100644 --- a/modules/package.py +++ b/modules/package.py @@ -23,7 +23,7 @@ from os.path import split from base.base import log from base.dirfactory import DirFactory from base.exceptions import ExecutionException -from base.util import pwd, copy, move +from base.util import pwd, copy, move, symlink from base.profiles import ver_rel, name from modules.directory import Directory @@ -32,9 +32,21 @@ class Package(Directory): # These two methods are here as examples. def load_dir(self, dir): super(Package, self).load_dir(dir) + self._check_sources() def make_dir(self, dir): super(Package, self).make_dir(dir) + self._check_sources() + + def _check_sources(self): + '''necessary to make sure self.sources is a list + ''' + if 'sources' not in self.cfg: + self.cfg['sources'] = list() + elif type(self.sources) is not list: + log.warn('sources for this package is not a list, overwriting!') + log.info('sources was, fyi, ' + str(self.sources)) + self.cfg['sources'] = list() def add_spec(self, spec_file): '''add's a spec file to the package, and sets the canonical package @@ -82,11 +94,41 @@ class Package(Directory): def sources(self): return self.cfg['sources'] + def copy_source(self, source_dir): + source = DirFactory(source_dir) + target_dir = join(self.dir, source.name) + if not source.dir == target_dir: + source.copy(target_dir) + self.add_source(source_dir) + + def move_source(self, source_dir): + source = DirFactory(source_dir) + target_dir = join(self.dir, source.name) + if not source.dir == target_dir: + source.move(target_dir) + self.add_source(source_dir) + def add_source(self, source_dir): source = DirFactory(source_dir) if not source.name in self.sources: self.cfg['sources'].append(source.name) + def rem_source(self, source): + self.cfg['sources'].remove(source) + + def del_source(self, source): + self.rem_source(source) + with pwd(self.dir): + rm(source) + + def fetch_sourceballs(self, profile=None): + pkg_srcen = self.sources + pkg_srcen = (DirFactory(pkg_src) for pkg_src in pkg_srcen) + with pwd(self.dir): + for pkg_src in pkg_srcen: + pkg_src.setup_sourceball(self.ver(profile)) + symlink(pkg_src.sourceball_loc, pkg_src.sourceball) + # These don't make sense anymore # TODO: Figure out the API to iterate over PackageSources where *args should be diff for each one # def source_dir(self, *args): diff --git a/modules/packagesource.py b/modules/packagesource.py index bfead67..95b3cca 100644 --- a/modules/packagesource.py +++ b/modules/packagesource.py @@ -56,10 +56,10 @@ class PackageSource(Directory): def sourceball_loc(self): return join(self.pkg_src_dir, self.sourceball) - def setup_sourceball(self): + def setup_sourceball(self, ver=''): raise NotImplementedError - def setup_sourceball_w_patches(self): + def setup_sourceball_w_patches(self, ver=''): raise NotImplementedError @property diff --git a/modules/sourceball.py b/modules/sourceball.py index 07a29e5..38abf1f 100644 --- a/modules/sourceball.py +++ b/modules/sourceball.py @@ -74,4 +74,11 @@ class SourceBall(PackageSource): elif len(args) == 1 and args[0] == 'orig': self.cfg['source'] = join(self.branch, self.orig_dir(self.name)) + def setup_sourceball(self, ver=''): + return + + def setup_sourceball_w_patches(self, ver=''): + raise NotImplementedError + + __all__ = ['SourceBall'] -- cgit