diff options
| author | Yaakov M. Nemoy <[email protected]> | 2009-05-03 07:22:14 (GMT) |
|---|---|---|
| committer | Yaakov M. Nemoy <[email protected]> | 2009-05-03 07:22:14 (GMT) |
| commit | 0881658ac29d5aa11904b3a97c31bf80d7ae4d85 (patch) | |
| tree | 003327771b257afc2b15af4136b7c69adacc2176 | |
| parent | 1c7fd121639331ebd649e93ace9a7ada21572100 (diff) | |
Removes direct calls to factories and replaces them with validators to more explicitely show what is intended to happenpredebian
| -rw-r--r-- | devshell/modules/build.py | 31 | ||||
| -rw-r--r-- | devshell/modules/buildsystem.py | 15 | ||||
| -rw-r--r-- | devshell/modules/cabal.py | 9 | ||||
| -rw-r--r-- | devshell/modules/mock.py | 20 | ||||
| -rw-r--r-- | devshell/modules/package.py | 42 | ||||
| -rw-r--r-- | devshell/modules/port.py | 9 | ||||
| -rw-r--r-- | devshell/modules/profile.py | 5 | ||||
| -rw-r--r-- | devshell/modules/sourceball.py | 2 |
8 files changed, 85 insertions, 48 deletions
diff --git a/devshell/modules/build.py b/devshell/modules/build.py index 7f5d3d6..f050c24 100644 --- a/devshell/modules/build.py +++ b/devshell/modules/build.py @@ -22,17 +22,22 @@ from os.path import join, abspath from os import walk from subprocess import Popen +import devshell.base.validators as validators + from devshell.base.base import log from devshell.base.profiles import dir_defines, join_defines, dist_defines from devshell.base.util import pwd, symlink, move, log_file -from devshell.base.validators import LimitedTypeValidator +from devshell.base.validators import LimitedTypeValidator, validate, path from devshell.modules.directory import Directory, DirFactory +from devshell.modules.package import PackageValidator +from devshell.modules.profile import ProfileValidator class Build(Directory): '''A wrapper around rpmbuild functions ''' + @validate(PackageValidator(1)) def setup_source(self, package): '''Given a package, set's it up in the buildroot for being built with rpmbuild @@ -40,7 +45,8 @@ class Build(Directory): returns nothing ''' - pkg = DirFactory(package) + pkg = package +# pkg = DirFactory(package) with pwd(pkg.dir): symlink(pkg.spec_file, join(self.dir, 'SPECS', pkg.spec_file)) @@ -49,6 +55,8 @@ class Build(Directory): log.debug(source) symlink(source, join(self.dir, 'SOURCES', source)) + @validate(PackageValidator(1)) + @validate(OptProfValidator(2)) def build_quick_rpm(self, package, profile=None): '''Builds an rpm on the local system using rpmbuild (aka no clean chroots) @@ -63,6 +71,8 @@ class Build(Directory): ''' self.rpmbuild('-ba', package, profile) + @validate(PackageValidator(1)) + @validate(OptProfValidator(2)) def build_source_rpm(self, package, profile=None): '''Builds an source rpm on the local system using rpmbuild @@ -80,7 +90,9 @@ class Build(Directory): ''' self.rpmbuild('-bs', package, profile) - def rpmbuild(self, param, package, profile=None): + @validate(PackageValidator(2)) + @validate(OptProfValidator(3)) + def rpmbuild(self, param, package, profile): '''The work horse of building rpms Given a directive param for rpmbuild, the package, and a possible @@ -91,7 +103,8 @@ class Build(Directory): returns nothing ''' - pkg = DirFactory(package) + pkg = package +# pkg = DirFactory(package) log.debug(package) log.debug(pkg) if profile: @@ -112,6 +125,7 @@ class Build(Directory): p.wait() log.debug(p.returncode) + @validate(path(1)) def fetch_rpms(self, target_dir): '''fetches all rpm files from the buildroot to another target directory @@ -122,13 +136,17 @@ class Build(Directory): target_dir is a path to the destination for all the rpms ''' - target_dir = abspath(target_dir) +# target_dir = abspath(target_dir) + log.debug('in fetch_rpms the path ' + target_dir + ' should be an absolute path') + if not target_dir.startswith('/'): + raise ExecutionException('target_dir in fetch_rpms of Build is not absolute') with pwd(self.dir): for path, dirs, files in walk('.'): for f in files: if f.endswith('.rpm'): move(join(path, f), join(target_dir, f)) + @validate(PackageValidator(1)) def fetch_build(self, package): '''fetches the built source tree from the execution of rpmbuild for review @@ -138,7 +156,8 @@ class Build(Directory): package is a directory name to a Package (Directory). ''' - pkg = DirFactory(package) + pkg = package +# pkg = DirFactory(package) with pwd(self.dir): source = pkg.cfg['source'] move(join('BUILD', source), join(pkg.dir, 'results')) diff --git a/devshell/modules/buildsystem.py b/devshell/modules/buildsystem.py index 1b604c2..a0cb99d 100644 --- a/devshell/modules/buildsystem.py +++ b/devshell/modules/buildsystem.py @@ -21,11 +21,12 @@ from os.path import join from contextlib import contextmanager import devshell.base.factories as factories - +import devshell.base.validators as validators from devshell.base.module import Module from devshell.base.util import log_file from devshell.modules.directory import DirFactory +from devshell.modules.packagesource import PackageSourceValidator class MetaBuildSystem(type): def __init__(cls, name, bases, attrs): @@ -35,13 +36,11 @@ class MetaBuildSystem(type): class BuildSystem(Module): __metaclass__ = MetaBuildSystem - def __init__(self, name): - if type(name) is str: - self.pkg_src = DirFactory(name) - self.name = name - else: - self.pkg_src = name - self.name = name.name + + @validators.validate(PackageSourceValidator(1)) + def __init__(self, pkg_src): + self.pkg_src = pkg_src + self.name = pkg_src.name def prepare(self, install=False, force=False, *args): '''runs the preparation/distribution stage of a build system diff --git a/devshell/modules/cabal.py b/devshell/modules/cabal.py index 8b44a54..68c98b2 100644 --- a/devshell/modules/cabal.py +++ b/devshell/modules/cabal.py @@ -36,16 +36,13 @@ class Cabal(BuildSystem): This provides a useful api for other modules around the cabal build system ''' - def init(self, name, cwd): + def __init__(self, pkg_src): '''creates a new cabal module - this api is deprecated, because it should be more autodetecting - - name is a Package (Directory) that uses cabal for its build system + pkg_src is a PackageSource (Directory) that uses cabal for its build system ''' - BuildSystem.init(name, cwd) + BuildSystem.__init__(self, pkg_src) self.compiler = haskell_compiler - def find_setup(self): '''returns the name of the Setup.?hs script for cabal. diff --git a/devshell/modules/mock.py b/devshell/modules/mock.py index f9aa78b..2d32aaf 100644 --- a/devshell/modules/mock.py +++ b/devshell/modules/mock.py @@ -19,20 +19,24 @@ from __future__ import with_statement from subprocess import Popen +import devshell.base.validators as validators + from devshell.base.base import log from devshell.base.module import Module from devshell.base.util import pwd, log_file -from devshell.modules.build import Build +from devshell.modules.build import Build, BuildValidator from devshell.modules.directory import DirFactory -from devshell.modules.package import Package -from devshell.modules.profile import Profile +from devshell.modules.package import Package, PackageValidator +from devshell.modules.profile import Profile, ProfileValidator class Builder(Module): pass class Mock(Builder): '''wrapper around mock for integrating with profiles and packages''' + @validators.validate(ProfileValidator(1)) + @validators.validate(BuildValidator(2)) def init(self, profile, build): '''initializer @@ -40,11 +44,12 @@ class Mock(Builder): build is a path to a buildroot directory ''' Builder.init(self) - self.builder = Build(build) - self.profile = Profile(profile) + self.builder = build + self.profile = profile + @validators.validate(PackageValidator(1)) def build(self, package): - pkg = DirFactory(package) + pkg = package srpm_name = pkg.get_srpm_name(self.profile) mock_cfg = self.profile.mock_cfg @@ -64,9 +69,10 @@ class Mock(Builder): log.info('mock compiling %s... please wait' % srpm_name) p.communicate() + @validators.validate(PackageValidator(1)) def build_rpm(self, package): '''builds an rpm from some package''' - pkg = DirFactory(package) + pkg = package self.builder.setup_source(package) self.builder.build_source_rpm(package, self.profile) diff --git a/devshell/modules/package.py b/devshell/modules/package.py index fee1d8f..5221572 100644 --- a/devshell/modules/package.py +++ b/devshell/modules/package.py @@ -21,6 +21,8 @@ from __future__ import with_statement from os.path import basename, abspath, join from contextlib import contextmanager +import devshell.base.validators as validators + from devshell.base.base import log from devshell.base.exceptions import ExecutionException from devshell.base.util import pwd, copy, move, symlink, rm @@ -28,6 +30,8 @@ from devshell.base.validators import LimitedTypeValidator from devshell.base.rpm_utils import RPMSpec from devshell.modules.directory import Directory, DirFactory +from devshell.modules.packagesource import PackageSourceValidator +from devshell.modules.profile import ProfileValidator class Package(Directory): # These two methods are here as examples. @@ -89,13 +93,15 @@ class Package(Directory): def set_pkg_name(self, name): self.cfg['pkg_name'] = name + @validators.validate(ProfileValidator(1)) def get_srpm_name(self, profile): '''given a profile, determines that the source rpm should be called''' with self.rpm_obj(self.spec_file, profile.dist_defines) as rpm: ver, rel = rpm.ver_rel() return '%s-%s-%s.src.rpm' % (self.pkg_name, ver, rel) - def ver(self, profile=None): + @validators.validate(OptProfValidator(1)) + def ver(self, profile): '''given a profile, determines the version of the current spec file''' with self.rpm_obj(self.spec_file, profile.dist_defines if profile else '') as rpm: return rpm.version() @@ -123,38 +129,41 @@ class Package(Directory): def sources(self): return self.cfg['sources'] - def copy_source(self, source_dir): - source = DirFactory(source_dir) + @validators.validate(PackageSourceValidator(1)) + def copy_source(self, source): target_dir = join(self.dir, source.name) if not source.dir == target_dir: source.copy(target_dir) - self.add_source(source_dir) + self.add_source(source) - def move_source(self, source_dir): - source = DirFactory(source_dir) + @validators.validate(PackageSourceValidator(1)) + def move_source(self, source): target_dir = join(self.dir, source.name) if not source.dir == target_dir: source.move(target_dir) - self.add_source(source_dir) + self.add_source(source) - def add_source(self, source_dir): - source = DirFactory(source_dir) + @validators.validate(PackageSourceValidator(1)) + def add_source(self, source): if not source.name in self.sources: self.cfg['sources'].append(source.name) + @validators.validate(PackageSourceValidator(1)) def rem_source(self, source): - self.cfg['sources'].remove(source) + self.cfg['sources'].remove(source.name) + @validators.validate(PackageSourceValidator(1)) def del_source(self, source): self.rem_source(source) with pwd(self.dir): - rm(source) + rm(source.dir) - def set_primary_source(self, source_dir): + @validators.validate(PackageSourceValidator(1)) + def set_primary_source(self, source): source = DirFactory(source_dir) - self.add_source(source_dir) + self.add_source(source) self.cfg['primary_source'] = source.name - self.get_spec_from_source(source_dir) + self.get_spec_from_source(source) @property def primary_source(self): @@ -164,6 +173,7 @@ class Package(Directory): def primary_source_pkg(self): return DirFactory(self.primary_source) + @validators.validate(OptProfValidator(1)) def fetch_sourceballs(self, profile=None, regen=True): pkg_srcen = self.sources pkg_srcen = (DirFactory(pkg_src) for pkg_src in pkg_srcen) @@ -203,8 +213,8 @@ class Package(Directory): #TODO: Check for valid port self.cfg['port'] = port - def get_spec_from_source(self, source_dir, file_name=None): - source = DirFactory(source_dir) + @validators.validate(PackageSourceValidator(1)) + def get_spec_from_source(self, source, file_name=None): if not file_name: file_name = join(source.source_dir, self.spec_file) else: diff --git a/devshell/modules/port.py b/devshell/modules/port.py index 93abc3e..8babb52 100644 --- a/devshell/modules/port.py +++ b/devshell/modules/port.py @@ -36,6 +36,7 @@ from devshell.modules.profile import Profile from devshell.modules.mock import Mock class Port(Module): + #TODO: replace this with a validator @classmethod def massage(cls, package=None): if not package: @@ -154,9 +155,11 @@ class Port(Module): tar_file.close() rm(tmp_dir) - def build_source_rpm(self, build, profile): - builder = Build(build) - profile = Profile(profile) + @validators.validate(BuildValidator(1)) + @validators.validate(ProfileValidator(2)) + def build_source_rpm(self, builder, profile): +# builder = Build(build) +# profile = Profile(profile) builder.setup_source(self.pkg.dir) self.prepare_sourceballs() builder.build_source_rpm(self.pkg.dir, profile) diff --git a/devshell/modules/profile.py b/devshell/modules/profile.py index 2aaaab5..6b4f397 100644 --- a/devshell/modules/profile.py +++ b/devshell/modules/profile.py @@ -19,6 +19,8 @@ from __future__ import with_statement from os.path import join +import devshell.base.validators as validators + from devshell.base.exceptions import ExecutionException from devshell.base.profiles import dist_defines, get_mock_cfg, distro, TARGET, DIST, DISTVAR, DISTVAL from devshell.base.util import pwd, copytree @@ -94,5 +96,6 @@ class Profile(Directory): Profile = DirFactory.register(Profile) ProfileValidator = LimitedTypeValidator(Profile, DirFactory, (str, )) +OptProfValidator = validators.Fallback(ProfileValidator, None, None) -__all__ = ['Profile'] +__all__ = ['Profile', 'ProfileValidator', 'OptProfValidator'] diff --git a/devshell/modules/sourceball.py b/devshell/modules/sourceball.py index 278aac5..c2c68a3 100644 --- a/devshell/modules/sourceball.py +++ b/devshell/modules/sourceball.py @@ -76,7 +76,7 @@ class SourceBall(PackageSource): move(self.name, self.orig_dir(self.name)) with pwd(self.pkg_src_dir): move(sourceball_name, basename(sourceball_name)) - self.cfg['sourceball'] = sourceball_name + self.cfg['sourceball'] = basename(sourceball_name) self.set_cur_to('head') def orig_dir(self, dir): |

