diff options
author | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2008-10-05 02:13:58 -0400 |
---|---|---|
committer | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2008-10-05 02:13:58 -0400 |
commit | d8471caa6b855a41aef8109108627f60f97c8f15 (patch) | |
tree | b2ea700594a48370011f959d5bb789b6e8aba45c /modules | |
parent | 0abf50482d83242e4c94545ffb2e66d3ff8ab6cc (diff) | |
download | fedora-devshell-d8471caa6b855a41aef8109108627f60f97c8f15.tar.gz fedora-devshell-d8471caa6b855a41aef8109108627f60f97c8f15.tar.xz fedora-devshell-d8471caa6b855a41aef8109108627f60f97c8f15.zip |
Unifying how modules get at information like state, and which dir they work on
Diffstat (limited to 'modules')
-rw-r--r-- | modules/package.py | 90 |
1 files changed, 51 insertions, 39 deletions
diff --git a/modules/package.py b/modules/package.py index cb0548e..8072938 100644 --- a/modules/package.py +++ b/modules/package.py @@ -1,64 +1,76 @@ +from __future__ import with_statement import tarfile from os import makedirs, getcwd, chdir from shutil import copyfileobj, copytree from os.path import abspath, join, split, splitext, basename +from configobj import ConfigObj from base.module import Module from base.base import log from base.exceptions import ExecutionException +from base.util import pwd, copy #TODO: Find universal library for parsing URLs and PATHs alike class Package(Module): def __init__(self, name=None): if not name: + log.debug(split(getcwd())) + name = split(getcwd())[1] + self.code_dir = getcwd() #detect name somehow - pass - # TODO: the following - #check location - #determine type of package - # to configure commands + else: + try: + cfg = ConfigObj('.devshell') + if cfg['type'] == 'package': + self.code_dir = getcwd() + except: + self.code_dir = abspath(name) + with pwd(self.code_dir): + self.pkg_cfg = ConfigObj('.devshell') + if not self.pkg_cfg['type'] == 'package': + raise ExecutionException('invalid package directory') self.name = name def create(self, name): if not self.name: makedirs(join(getcwd(), name)) - def add_spec(self, spec_file, name=None): + def add_spec(self, spec_file): log.debug('spec_file is %s' % spec_file) - log.debug('name might be %s' % name) - if self.name: - name = self.name - log.debug('spec_file_name is %s' % name + '.spec') - try: - # we're using copyfileobj so later we can do this from a URL - src = file(spec_file, 'rb') - dst = file(join(getcwd(), name, name + '.spec'), 'wb') - copyfileobj(src, dst) - src.close() - dst.close() - except IOError, e: - log.error(str(e)) - raise ExecutionException(e, 'spec-file could not be added') + log.debug('spec_file_name is %s' % self.name + '.spec') + with pwd(self.code_dir): + try: + copy(spec_file, self.name) + except IOError, e: + log.error(str(e)) + raise ExecutionException(e, 'spec-file could not be added') - def add_sourceball(self, sourceball_name, name=None, extract_dir=None): - if self.name: - name = self.name - #TODO: this is temporary - else: - log.debug(abspath(name)) - chdir(abspath(name)) - try: - sourceball = tarfile.open(sourceball_name) - if not extract_dir: - extract_dir = min([(x.name, x) for x in sourceball])[0] - extract_dir = basename(abspath(extract_dir)) - log.debug('extract_dir is %s' % extract_dir) - orig_extract_dir = extract_dir + '_orig' - sourceball.extractall() - copytree(abspath(extract_dir), abspath(orig_extract_dir)) - finally: - #TODO: figure out what exceptions TarFile will throw - pass
\ No newline at end of file + def add_sourceball(self, sourceball_name, extract_dir=None): + with pwd(self.code_dir): + try: + copy(sourceball_name, split(sourceball_name)[1]) + sourceball_name = split(sourceball_name)[1] + + self.pkg_cfg['sourceball'] = sourceball_name + sourceball = tarfile.open(sourceball_name) + if not extract_dir: + extract_dir = min([(x.name, x) for x in sourceball])[0] + extract_dir = basename(abspath(extract_dir)) + log.debug('extract_dir is %s' % extract_dir) + self.pkg_cfg['source'] = extract_dir + orig_extract_dir = extract_dir + '_orig' + sourceball.extractall() + copytree(abspath(extract_dir), abspath(orig_extract_dir)) + except OSError, e: + #TODO: Fill this in with something better + #Chances are the _orig dir already exists + raise ExecutionException(e, 'something went wrong') + #TODO: figure out what exceptions TarFile will throw + + def close(self): + self.pkg_cfg.write() + +__all__ = ['Package']
\ No newline at end of file |