diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/darcs.py | 113 | ||||
-rw-r--r-- | modules/package.py | 34 | ||||
-rw-r--r-- | modules/packagesource.py | 63 | ||||
-rw-r--r-- | modules/revisioncontrol.py | 4 | ||||
-rw-r--r-- | modules/sourceball.py | 28 |
5 files changed, 160 insertions, 82 deletions
diff --git a/modules/darcs.py b/modules/darcs.py index 8bee4a4..943ebf0 100644 --- a/modules/darcs.py +++ b/modules/darcs.py @@ -18,11 +18,12 @@ from __future__ import with_statement +import os import re from contextlib import contextmanager from os import getcwd -from os.path import join +from os.path import join, basename, exists from subprocess import Popen, PIPE from base.util import pwd, log, rm, log_file, copy, move @@ -35,6 +36,49 @@ class Darcs(RevisionControl): '''manages single source packages where the primary source is darcs ''' _type = 'darcs' + def __init__(self, name=None, url=None, *args): + if url: + #split chokes on URLs that end in a / + url = url[:-1] if url.endswith('/') else url + tgt = basename(url) + if not name: + name = tgt + self.get(url, tgt, *args) + super(Darcs, self).__init__(name) + if url: + self.cfg['vc_url'] = url + self.cfg['hackage_name'] = tgt + self.cfg['source'] = '.' + with pwd(self.branch_dir): + self.get(self.dir, 'orig') + + + def get(self, src, tgt, *args): + '''sets up a branch given arguments, taken from a source with a target + + the idioms of branching in different VCSes vary, and a common + api for this in devshell has not yet been realized + + currently, this creates a new temporary local branch in darcs + and sets the source to it + ''' + with log_file('darcs.log') as darcs_out: + # NB: args is a tuple, must be converted + p = Popen(['darcs', 'get'] + list(args) + [src, tgt], + stdout = darcs_out, stderr = darcs_out) + 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 @@ -46,7 +90,7 @@ class Darcs(RevisionControl): @property def hackage_name(self): '''assuming this package is a haskell package, what is the canonical name - + this name may be changed in the future ''' return self.cfg['hackage_name'] @@ -54,7 +98,7 @@ class Darcs(RevisionControl): def source(self, *args): '''the name of the directory where the source is being kept currently - hackage_name is the canonical name of the package, this is + hackage_name is the canonical name of the package, this is just for handling branching and other nasty devilish tricks ''' return self.cfg['source'] @@ -80,45 +124,16 @@ class Darcs(RevisionControl): if args: rm(self.cfg['source']) self.cfg['source'] = old_src - self.set_current_head() + self.set_current_src() - def get(self, src, tgt, *args): - '''sets up a branch given arguments, taken from a source with a target - - the idioms of branching in different VCSes vary, and a common - api for this in devshell has not yet been realized - - currently, this creates a new temporary local branch in darcs - and sets the source to it - ''' - with pwd(self.dir): - self.cfg['source'] = tgt - with log_file('darcs.log') as darcs_out: - p = Popen(['darcs', 'get'] + list(args) + [src, tgt], - stdout = darcs_out, stderr = darcs_out) - log.info('darcs get %s %s, please wait....' % (src, tgt)) - p.wait() - self.set_current_head() - - 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.cfg['hackage_name'] = split(tgt)[1] - self.get(url, tgt, *args) - - def set_current_head(self): + def set_current_src(self): '''sets the current internal state to reflect the current head chances are, the user should rarely mess with this. - this may change, because rather than using .patch files for rpm - handling, we may ask the user to commit all the changes to darcs, + this may change, because rather than using .patch files for rpm + handling, we may ask the user to commit all the changes to darcs, and then have devshell generate .patch files automatically instead ''' log.debug(getcwd()) @@ -130,16 +145,30 @@ class Darcs(RevisionControl): date = date_re.search(change).groups()[0] self.cfg['head'] = (hash, date) - def set_cur_to(self, *args): + def set_cur_to(self, *args, branch_name=''): '''passes arbitrary args to darcs get and makes a branch out of it - + this is not really optimal, because it only does things temporary, - we need to look at as systematic way to handle branching. + we need to look at as systematic way to handle branching. looking at a potential git and a potential cvs module may help ''' - cur_src_dir = self.cfg['source'] - new_src_dir = cur_src_dir + '_tmp' - self.get(cur_src_dir, new_src_dir, *args) + if len(args) == 1 and args[0] == 'head': + self.cfg['source'] = '.' + if len(args) == 2 and args[0] == 'branch': + self.cfg['source'] = join(self.branch, args[1]) + else: + index = hash(args) + index_dir = join(self.branch, index) + with pwd(self.dir): + if not exists(index_dir): + self.get(self.source(), index_dir, *args) + self.cfg['source'] = index_dir + if branch_name: + with pwd(self.branch_dir): + self.get(index, branch_name) +# cur_src_dir = self.cfg['source'] +# new_src_dir = cur_src_dir + '_tmp' +# self.get(cur_src_dir, new_src_dir, *args) def set_cur_to_patch(self, hash): '''sets the current branch to fork off a particular hash''' diff --git a/modules/package.py b/modules/package.py index af0a48e..8fdeb93 100644 --- a/modules/package.py +++ b/modules/package.py @@ -21,15 +21,14 @@ from __future__ import with_statement 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.profiles import ver_rel, name from modules.directory import Directory - class Package(Directory): - _type = 'package' # These two methods are here as examples. def load_dir(self, dir): super(Package, self).load_dir(dir) @@ -79,17 +78,28 @@ class Package(Directory): ver, rel = ver_rel(self.spec_file, profile.dist_defines if profile else '') return ver - def source_dir(self, *args): - '''provides an absolute pathname for where the primary source is unpacked''' - return join(self.dir, self.source(*args)) + @property + def sources(self): + return self.cfg['sources'] + + def add_source(self, source_dir): + source = DirFactory(source_dir) + if not source.name in self.sources: + self.cfg['sources'].append(source.name) + +# 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): +# '''provides an absolute pathname for where the primary source is unpacked''' +# return join(self.dir, self.source(*args)) - def source(self, *args): - '''base method that should return where the source is kept to some yet unknown criteria''' - raise NotImplementedError +# def source(self, *args): +# '''base method that should return where the source is kept to some yet unknown criteria''' +# raise NotImplementedError - @property - def sourceball(self): - '''the current sourceball in use, for building packages''' - return self.cfg['sourceball'] +# @property +# def sourceball(self): +# '''the current sourceball in use, for building packages''' +# return self.cfg['sourceball'] __all__ = ['Package'] diff --git a/modules/packagesource.py b/modules/packagesource.py new file mode 100644 index 0000000..e6c8d99 --- /dev/null +++ b/modules/packagesource.py @@ -0,0 +1,63 @@ +# Fedora Developer Shell +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Authors: Yaakov M. Nemoy <ynemoy@redhat.com> +# + +from modules.directory import directory + +class PackageSource(Directory): + + def make_dir(self, dir): + super(PackageSource, self).make_dir(dir) + with pwd(dir): + makedirs('.pkg_src') + + @property + def pkg_src(self): + return '.pkg_src' + + @property + def pkg_src_dir(self): + return join(self.dir, self.pkg_src) + + @property + def branch(self): + return join(self.pkg_src, 'branches') + + @property + def branch_dir(self): + return join(self.dir, self.branch) + + @property + def sourceball(self): + return self.cfg['sourceball'] + + @property + def sourceball_loc(self): + return join(self.parent, self.sourceball) + + def setup_sourceball(self): + raise NotImplementedError + + def setup_sourceball_w_patches(self): + raise NotImplementedError + + def source(self, *args): + raise NotImplementedError + + def source_dir(self, *args): + return join(self.dir, self.source(*args)) + diff --git a/modules/revisioncontrol.py b/modules/revisioncontrol.py index 80efaa2..e5d200a 100644 --- a/modules/revisioncontrol.py +++ b/modules/revisioncontrol.py @@ -16,9 +16,9 @@ # Authors: Yaakov M. Nemoy <ynemoy@redhat.com> # -from modules.package import Package +from modules.packagesource import PackageSource -class RevisionControl(Package): +class RevisionControl(PackageSource): '''base class for any module that implements a VCS system and wraps it for getting source for packages''' pass diff --git a/modules/sourceball.py b/modules/sourceball.py index d66277e..60fee9f 100644 --- a/modules/sourceball.py +++ b/modules/sourceball.py @@ -30,7 +30,7 @@ from base.exceptions import ExecutionException from base.util import pwd, copy, move from modules.dirfactory import DirFactory -from modules.package import PackageSource +from modules.packagesource import PackageSource class SourceBall(PackageSource): '''a type of package that is a single sourceball, a spec file, and some patches''' @@ -58,27 +58,6 @@ class SourceBall(PackageSource): move(join(tmp_dir, sourceball_name), sourceball_name) self.cfg['sourceball'] = sourceball_name - def make_dir(self, dir): - super(PackageSource, self).make_dir(dir) - with pwd(dir): - makedirs('.pkg_src') - - @property - def branch(self): - return join('.pkg_src', 'branches') - - @property - def branch_dir(self): - return join(self.dir, self.branch) - - @property - def sourceball(self): - return self.cfg['sourceball'] - - @property - def sourceball_loc(self): - return join(self.parent, self.sourceball) - def orig_dir(self, dir): '''where is the original source kept @@ -92,12 +71,9 @@ class SourceBall(PackageSource): you get the modified source ''' if args[0] == 'orig': - return join(self.branch, self.orig_dir(self.name))) + return join(self.branch, self.orig_dir(self.name)) else: return self.name - def source_dir(self, *args): - return join(self.dir, self.source(*args)) - __all__ = ['SourceBall'] |