diff options
author | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2009-01-05 02:16:29 -0500 |
---|---|---|
committer | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2009-01-05 02:16:29 -0500 |
commit | 5cada39e063281f8f0be7a55f4ce2d30ae5432a9 (patch) | |
tree | d2305f987bea1f098fe861baa22ab33aad966e01 /modules | |
parent | 1dd83c963c26d34ebe37bf74f36e8b9eaaf3ddfe (diff) | |
download | fedora-devshell-5cada39e063281f8f0be7a55f4ce2d30ae5432a9.tar.gz fedora-devshell-5cada39e063281f8f0be7a55f4ce2d30ae5432a9.tar.xz fedora-devshell-5cada39e063281f8f0be7a55f4ce2d30ae5432a9.zip |
Turned build into a Directory revolving around something akin to ~/rpmbuild
It was bugging me that we had to do all this autodetection, so now we have the code to get that for free. It changes the API around a bit.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/build.py | 96 | ||||
-rw-r--r-- | modules/directory.py | 8 | ||||
-rw-r--r-- | modules/dirfactory.py | 3 |
3 files changed, 42 insertions, 65 deletions
diff --git a/modules/build.py b/modules/build.py index de89d88..5481507 100644 --- a/modules/build.py +++ b/modules/build.py @@ -25,87 +25,65 @@ from subprocess import Popen from base.base import log from base.module import Module -from base.util import pwd, copy, symlink, move +from base.util import pwd, copy, symlink, move, log_file from base.exceptions import ExecutionException from base.vars import FEDORA_DIR from base.profiles import dir_defines, join_defines, dist_defines, Profile +from modules.directory import Directory +from modules.dirfactory import DirFactory from modules.package import Package -class Build(Module): - def __init__(self, name=None, target_dir=None): - log.debug('name is %s' % name) - self.name = name - self.pkg = Package(name) - self.target_dir = target_dir - - def setup_source(self, target_dir=None): - if not target_dir: - if self.target_dir: - target_dir = self.target_dir - else: - raise ExecutionException(None, 'no Target Dir specified') - log.debug('target dir is %s' % target_dir) - with pwd(self.pkg.code_dir): - symlink(self.name + '.spec', - join(self.target_dir, 'SPECS', self.name + '.spec')) - sball = self.pkg.pkg_cfg['sourceball'] - symlink(sball, join(self.target_dir, 'SOURCES', sball)) +class Build(Directory): + _type = 'build' + def setup_source(self, package): + pkg = DirFactory(package) + with pwd(pkg.dir): + symlink(pkg.spec_file, + join(self.dir, 'SPECS', pkg.spec_file())) + sball = pkg.cfg['sourceball'] + symlink(sball, join(self.dir, 'SOURCES', sball)) patches = [f for f in listdir(getcwd()) if f.endswith('.patch')] - for p in patches: - symlink(patch, join(self.target_dir, 'SOURCES', p)) + for patch in patches: + symlink(patch, join(self.dir, 'SOURCES', patch)) - def build_quick_rpm(self, target_dir=None): - self.rpmbuild('-ba', target_dir) + def build_quick_rpm(self): + self.rpmbuild('-ba') - def build_source_rpm(self, target_dir=None): - self.rpmbuild('-bs', target_dir) + def build_source_rpm(self): + self.rpmbuild('-bs') - def rpmbuild(self, param, target_dir=None, profile=None): - if not target_dir: - if self.target_dir: - target_dir = self.target_dir - else: - raise ExecutionException(None, 'no Target Dir specified') + def rpmbuild(self, param, package, profile=None): + pkg = DirFactory(package) if profile: defines = join_defines(profile.dist_defines, - dir_defines(target_dir)) + dir_defines(self.dir)) else: - defines = dir_defines(target_dir) - with pwd(self.pkg.code_dir): - with file('rpmbuild.log', 'w') as rpm_out: - with pwd(join(target_dir, 'SPECS')): + defines = dir_defines(self.dir) + with pwd(pkg.dir): + with log_file('rpmbuild.log') as rpm_out: + with pwd(join(self.dir, 'SPECS')): p = Popen(['rpmbuild', defines, param, - self.name + '.spec'], + pkg.spec_file], stdout=rpm_out, stderr=rpm_out) - log.info('building %s... please wait' % \ - self.pkg.spec_file()) + log.info('building %s... please wait' + % pkg.spec_file) p.wait() - def fetch_rpms(self, target_dir=None): - if not target_dir: - if self.target_dir: - target_dir = self.target_dir - else: - raise ExecutionException(None, 'no Target Dir specified') - with pwd(target_dir): + def fetch_rpms(self): + with pwd(self.dir): 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 move(join(path, f), join(FEDORA_DIR, f)) - def fetch_build(self, target_dir=None): - if not target_dir: - if self.target_dir: - target_dir = self.target_dir - else: - raise ExecutionException(None, 'no Target Dir specified') - with pwd(target_dir): - source = self.pkg.pkg_cfg['source'] - move(join('BUILD', source), join(self.pkg.code_dir, 'results')) + def fetch_build(self, package): + pkg = DirFactory(package) + with pwd(self.dir): + source = pkg.cfg['source'] + move(join('BUILD', source), join(pkg.dir, 'results')) - def close(self): - self.pkg.close() - __all__ = ['Build'] diff --git a/modules/directory.py b/modules/directory.py index 0b81842..40f288f 100644 --- a/modules/directory.py +++ b/modules/directory.py @@ -32,7 +32,7 @@ class Directory(Module): _type = 'directory' def __init__(self, name=None): if not name: - log.debug('no name with package') + log.debug('no name with directory') cwd = getcwd() log.debug(split(cwd)) if self.is_sysdir_dir(cwd): @@ -40,7 +40,7 @@ class Directory(Module): else: self.make_dir(cwd) else: - log.debug('package.init with name ' + name) + log.debug('directory.init with name ' + name) dir = abspath(name) if not exists(dir): makedirs(dir) @@ -66,15 +66,17 @@ class Directory(Module): with pwd(dir): self.cfg = ConfigObj('.devshell') self.name = self.cfg['name'] + self.parent = self.cfg['parent'] self.dir = self.cfg['dir'] def make_dir(self, dir): log.debug('directory.make_dir') with pwd(dir): self.cfg = ConfigObj('.devshell') - name = split(getcwd())[1] + 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.write() diff --git a/modules/dirfactory.py b/modules/dirfactory.py index 604067b..30d5e59 100644 --- a/modules/dirfactory.py +++ b/modules/dirfactory.py @@ -53,11 +53,8 @@ class DirFactory(Module): else: type = whatis_sysdir(dir) new_cls = dirs[type] - log.debug(new_cls) foo = new_cls.__new__(new_cls, name) foo.__init__(name) - log.debug(foo) - log.debug(foo.cfg) return foo def whatis_sysdir(dir): |