diff options
author | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2009-01-08 15:27:45 -0500 |
---|---|---|
committer | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2009-01-08 15:27:45 -0500 |
commit | 3bcae770792afe5d5fff2af127cad2c1d0d59d57 (patch) | |
tree | b89e5835589ebd222d42c46943e38452f9faa6c6 | |
parent | 84211749a73cbff248192519c0f458806b1fb065 (diff) | |
download | fedora-devshell-3bcae770792afe5d5fff2af127cad2c1d0d59d57.tar.gz fedora-devshell-3bcae770792afe5d5fff2af127cad2c1d0d59d57.tar.xz fedora-devshell-3bcae770792afe5d5fff2af127cad2c1d0d59d57.zip |
Got rid of non absolute _dir properties.
In effect, anything that ends in dir shoud usually return an absolute path. The absolute path is dynamically determined using utility functions based on the load time settings of a directory object. This both reduces the number of path ambiguities based on the cwd, and yet removes as many absolute paths from config files, so directory objects can be shared between workspaces and developers.
-rw-r--r-- | modules/build.py | 3 | ||||
-rw-r--r-- | modules/cabal.py | 12 | ||||
-rw-r--r-- | modules/darcs.py | 8 | ||||
-rw-r--r-- | modules/directory.py | 50 | ||||
-rw-r--r-- | modules/package.py | 13 | ||||
-rw-r--r-- | modules/sourceball.py | 6 |
6 files changed, 63 insertions, 29 deletions
diff --git a/modules/build.py b/modules/build.py index cc61868..7fcc1b0 100644 --- a/modules/build.py +++ b/modules/build.py @@ -79,9 +79,6 @@ class Build(Directory): for path, dirs, files in walk('.'): for f in files: if f.endswith('.rpm'): - #TODO: Gotta figure out what should be FEDORA_DIR - # Probably something involving "Project" or i dunno what - # it's something temporary for now, don't commi this move(join(path, f), join(target_dir, f)) def fetch_build(self, package): diff --git a/modules/cabal.py b/modules/cabal.py index 2e6d30b..529b023 100644 --- a/modules/cabal.py +++ b/modules/cabal.py @@ -57,8 +57,8 @@ class Cabal(Module): return one(listdir(getcwd()), setup_re.search) def compile_setup(self, orig=''): - log.debug('code_dir is ' + self.package.code_dir) - with pwd(self.package.code_dir): + log.debug('dir is ' + self.package.dir) + with pwd(self.package.dir): with log_file('ghc.log') as ghc_out: log.debug('ghc.log file is ' + str(ghc_out)) log.debug('source_dir is ' + self.package.source_dir(orig)) @@ -72,7 +72,7 @@ class Cabal(Module): def configure(self, target='home', orig=''): user = True if target == 'home' else False self.compile_setup(orig) - with pwd(self.package.code_dir): + with pwd(self.package.dir): with log_file('cabal.log') as cabal_out: log.debug('source_dir is ' + self.package.source_dir(orig)) with pwd(self.package.source_dir(orig)): @@ -85,7 +85,7 @@ class Cabal(Module): def build(self, orig=''): '''This is not safe to run on an unconfigured source dir''' self.compile_setup(orig) - with pwd(self.package.code_dir): + with pwd(self.package.dir): with log_file('cabal.log') as cabal_out: with pwd(self.package.source_dir(orig)): args = [abspath('Setup'), 'build'] @@ -96,7 +96,7 @@ class Cabal(Module): def install(self, orig=''): '''This is not safe to run on an unconfigured source dir''' self.compile_setup(orig) - with pwd(self.package.code_dir): + with pwd(self.package.dir): with log_file('cabal.log') as cabal_out: with pwd(self.package.source_dir(orig)): args = [abspath('Setup'), 'install'] @@ -135,7 +135,7 @@ class Cabal(Module): self.install_source(target, '') def source_dir(self, *args): - with pwd(self.package.code_dir): + with pwd(self.package.dir): return abspath(self.package.cfg['source'] + (self.orig_src_dir if original else "")) def latest_version(self, pkg): diff --git a/modules/darcs.py b/modules/darcs.py index 0921d3c..dddaee2 100644 --- a/modules/darcs.py +++ b/modules/darcs.py @@ -44,7 +44,7 @@ class Darcs(RevisionControl): def hackage_name(self): return self.cfg['hackage_name'] - def source_dir(self, *args): + def source(self, *args): return self.cfg['source'] @contextmanager @@ -109,6 +109,12 @@ class Darcs(RevisionControl): def hash(self): return self.cfg['head'][0] + def print_date(self): + log.info('The timestamp is ' + self.date) + + def print_hash(self): + log.info('The hash is ' + self.hash) + def set_cur_to_patch(self, hash): self.set_cur_to('--to-match', 'hash ' + hash) diff --git a/modules/directory.py b/modules/directory.py index 40f288f..139a2c9 100644 --- a/modules/directory.py +++ b/modules/directory.py @@ -25,9 +25,9 @@ from os.path import abspath, join, split, splitext, basename, exists, dirname from base.base import log from base.module import Module -from base.util import pwd +from base.util import pwd, copytree - +from modules.dirfactory import DirFactory class Directory(Module): _type = 'directory' def __init__(self, name=None): @@ -64,10 +64,15 @@ class Directory(Module): def load_dir(self, dir): log.debug('directory.load_dir') with pwd(dir): + parent, name = split(getcwd()) + self.parent = parent self.cfg = ConfigObj('.devshell') - self.name = self.cfg['name'] - self.parent = self.cfg['parent'] - self.dir = self.cfg['dir'] + if not self.name == name: + # we are saving name in the .devshell file so we can detect + # if the name has been changed or not. we don't want to have to run + # rename all the time + self.rename(name) + pass def make_dir(self, dir): log.debug('directory.make_dir') @@ -75,15 +80,44 @@ class Directory(Module): self.cfg = ConfigObj('.devshell') parent, name = split(getcwd()) self.cfg['type'] = self._type - self.cfg['name'] = self.name = name - self.cfg['parent'] = self.parent = parent - self.cfg['dir'] = self.dir = dir + self.cfg['name'] = name + self.parent = parent self.cfg.write() + @property + def name(self): + return self.cfg['name'] + + @property + def parent(self): + return self.cfg['parent'] + + @property + def dir(self): + return join(self.parent, self.name) + def close(self): log.debug('writing self.cfg for directory') with pwd(self.dir): self.cfg.write() + def rename(self, new_name): + self.cfg['name'] = new_name + + def move(self, new_loc): + new_loc = abspath(new_loc) + new_parent, new_name = split(new_loc) + old_dir = self.dir + copytree(self.dir, new_loc) + self.parent = new_parent + self.rename(new_name) + rm(old_dir) + + def copy(self, new_loc): + new_loc = abspath(new_loc) + new_parent, new_name = split(new_loc) + copytree(self.dir, new_loc) + new_dir = DirFactory(new_loc) + return new_dir __all__ = ['Directory'] diff --git a/modules/package.py b/modules/package.py index 983a2aa..c697067 100644 --- a/modules/package.py +++ b/modules/package.py @@ -43,7 +43,7 @@ class Package(Directory): #TODO: get the spec file name, copy # Then get the actual package name and set pkg_name to the right one spec_fname = split(spec_file)[1] - with pwd(self.code_dir): + with pwd(self.dir): try: copy(spec_file, spec_fname) self.cfg['pkg_name'] = name(spec_fname) @@ -58,17 +58,11 @@ class Package(Directory): return self.pkg_name + '.spec' @property - def code_dir(self): - # this is a hack for some refactoring backwards compatibility - #TODO: replace code_dir with just dir - return self.cfg['dir'] - - @property def pkg_name(self): return self.cfg['pkg_name'] def get_srpm_name(self, profile): - with pwd(self.code_dir): + with pwd(self.dir): ver, rel = ver_rel(self.spec_file, profile.dist_defines) return '%s-%s-%s.src.rpm' % (self.pkg_name, ver, rel) @@ -78,6 +72,9 @@ class Package(Directory): return ver def source_dir(self, *args): + return join(self.dir, self.source(*args) + + def source(self, *args): raise NotImplementedError @property diff --git a/modules/sourceball.py b/modules/sourceball.py index 8364eda..4a39e94 100644 --- a/modules/sourceball.py +++ b/modules/sourceball.py @@ -19,7 +19,7 @@ from __future__ import with_statement import tarfile -from os.path import abspath, split, basename +from os.path import abspath, split, basename, join from shutil import copytree from subprocess import Popen, PIPE @@ -34,14 +34,14 @@ class SourceBall(Package): def orig_dir(self, dir): return dir + '_orig' - def source_dir(self, *args): + def source(self, *args): if args[0] == 'orig': return self.orig_dir(self.cfg['source']) else: return self.cfg['source'] def add_sourceball(self, sourceball_name, extract_dir=None): - log.debug('addincg sourceball with code_dir ' + self.code_dir) + log.debug('addincg sourceball with dir ' + self.dir) with pwd(self.dir): try: sourceball_name = copy(sourceball_name, |