diff options
author | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2009-01-18 22:21:05 -0500 |
---|---|---|
committer | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2009-01-18 22:21:05 -0500 |
commit | d3d01a3237b1767f61953e34879dffd16667b769 (patch) | |
tree | 360c9a4d5131580cbbd42973f5a98ef9e2d04a02 | |
parent | 2582dbfd415494a7fa5b378082b0aba19e6d88c1 (diff) | |
download | fedora-devshell-d3d01a3237b1767f61953e34879dffd16667b769.tar.gz fedora-devshell-d3d01a3237b1767f61953e34879dffd16667b769.tar.xz fedora-devshell-d3d01a3237b1767f61953e34879dffd16667b769.zip |
Modifies factories, adds a BuildSystemFactory
BSFactory, oh yeah!
-rw-r--r-- | base/factories.py (renamed from base/dirfactory.py) | 16 | ||||
-rw-r--r-- | modules/build.py | 2 | ||||
-rw-r--r-- | modules/buildsystem.py | 15 | ||||
-rw-r--r-- | modules/cabal.py | 9 | ||||
-rw-r--r-- | modules/darcs.py | 7 | ||||
-rw-r--r-- | modules/directory.py | 6 | ||||
-rw-r--r-- | modules/haskellport.py | 2 | ||||
-rw-r--r-- | modules/mock.py | 2 | ||||
-rw-r--r-- | modules/package.py | 2 | ||||
-rw-r--r-- | modules/packagesource.py | 13 | ||||
-rw-r--r-- | modules/sourceball.py | 1 |
11 files changed, 51 insertions, 24 deletions
diff --git a/base/dirfactory.py b/base/factories.py index 57d66db..98022fe 100644 --- a/base/dirfactory.py +++ b/base/factories.py @@ -27,10 +27,24 @@ from exceptions import ExecutionException directory_type = dict() -def register(cls, name): +def register_dirfactory(cls, name): global directory_type directory_type[name] = cls +buildsystem_type = dict() + +def register_buildsystem(cls, name): + global buildsystem_type + buildsystem_type[name] = cls + +class BuildSystemFactory(object): + def __new__(cls, type, *args): + new_cls = buildsystem_type[type] + foo = new_cls.__new__(new_cls, *args) + foo.__init__(*args) + return foo + + class DirFactory(object): '''creates a new object of type defined by a directory's .devshell file''' def __new__(cls, name=None): diff --git a/modules/build.py b/modules/build.py index 1eba2da..3060b57 100644 --- a/modules/build.py +++ b/modules/build.py @@ -24,7 +24,7 @@ from os import listdir, getcwd, walk from subprocess import Popen from base.base import log -from base.dirfactory import DirFactory +from base.factories import DirFactory from base.exceptions import ExecutionException from base.module import Module from base.profiles import dir_defines, join_defines, dist_defines, Profile diff --git a/modules/buildsystem.py b/modules/buildsystem.py index dbedbfc..5265101 100644 --- a/modules/buildsystem.py +++ b/modules/buildsystem.py @@ -18,7 +18,22 @@ from base.module import Module +class MetaBuildSystem(type): + def __init__(cls, name, bases, attrs): + t = name.lower() + cls._type = t + factories.register_buildsystem(cls, t) + class BuildSystem(Module): + __metaclass__ = MetaBuildSystem + def __init__(self, name): + if type(name) is string: + self.pkg_src = DirFactory(name) + self.name = name + else: + self.pkg_src = name + self.name = name.name + def configure(self, target='home', *args): '''runs the configure stage of cabal diff --git a/modules/cabal.py b/modules/cabal.py index a993326..fc9bc4f 100644 --- a/modules/cabal.py +++ b/modules/cabal.py @@ -28,7 +28,7 @@ from urllib import urlopen, urlretrieve from base.base import log from base.exceptions import ExecutionException -from base.dirfactory import DirFactory +from base.factories import DirFactory from base.util import pwd, one, log_file from base.vars import orig_src_dir, haskell_compiler @@ -47,12 +47,7 @@ class Cabal(BuildSystem): name is a Package (Directory) that uses cabal for its build system ''' - if type(name) is string: - self.pkg_src = DirFactory(name) - self.name = name - else: - self.pkg_src = name - self.name = name.name + super(Cabal, self).__init__(name) self.compiler = haskell_compiler def find_setup(self): diff --git a/modules/darcs.py b/modules/darcs.py index 010cecc..68bea98 100644 --- a/modules/darcs.py +++ b/modules/darcs.py @@ -85,13 +85,6 @@ class Darcs(RevisionControl): ''' return self.cfg['hackage_name'] - @property - def buildsystem(self): - return self.cfg['buildsystem'] - - def set_buildsystem(self, buildsystem): - self.cfg['buildsystem'] = buildsystem - def set_current_src(self): '''sets the current internal state to reflect the current head diff --git a/modules/directory.py b/modules/directory.py index 2692f06..e71192a 100644 --- a/modules/directory.py +++ b/modules/directory.py @@ -19,14 +19,14 @@ from __future__ import with_statement -import base.dirfactory as dirfactory +import base.factories as factories from configobj import ConfigObj from os import makedirs, getcwd, listdir from os.path import abspath, join, split, splitext, basename, exists, dirname from base.base import log -from base.dirfactory import DirFactory +from base.factories import DirFactory from base.module import Module from base.util import pwd, copytree @@ -34,7 +34,7 @@ class MetaDirectory(type): def __init__(cls, name, bases, attrs): t = name.lower() cls._type = t - dirfactory.register(cls, t) + factories.register_directory(cls, t) class Directory(Module): '''a generic base class for any module that has to maintain state diff --git a/modules/haskellport.py b/modules/haskellport.py index 76eb48f..553b47c 100644 --- a/modules/haskellport.py +++ b/modules/haskellport.py @@ -21,7 +21,7 @@ from os import getcwd from base.base import log from base.exceptions import ExecutionException -from base.dirfactory import DirFactory +from base.factories import DirFactory from base.util import pwd from modules.darcs import Darcs diff --git a/modules/mock.py b/modules/mock.py index 9bd88e3..b72b1a6 100644 --- a/modules/mock.py +++ b/modules/mock.py @@ -20,7 +20,7 @@ from __future__ import with_statement from subprocess import Popen from base.base import log -from base.dirfactory import DirFactory +from base.factories import DirFactory from base.module import Module from base.profiles import ver_rel from base.util import pwd, log_file diff --git a/modules/package.py b/modules/package.py index 2e46add..e53f0dd 100644 --- a/modules/package.py +++ b/modules/package.py @@ -21,7 +21,7 @@ from __future__ import with_statement from os.path import split from base.base import log -from base.dirfactory import DirFactory +from base.factories import DirFactory from base.exceptions import ExecutionException from base.util import pwd, copy, move, symlink from base.profiles import ver_rel, name diff --git a/modules/packagesource.py b/modules/packagesource.py index 1e88311..2b320ca 100644 --- a/modules/packagesource.py +++ b/modules/packagesource.py @@ -21,12 +21,12 @@ from contextlib import contextmanager from os import makedirs from os.path import join +from base.factories import BuildSystemFactory from base.util import pwd from modules.directory import Directory class PackageSource(Directory): - def make_dir(self, dir): super(PackageSource, self).make_dir(dir) with pwd(dir): @@ -108,3 +108,14 @@ class PackageSource(Directory): def branch_dir(self, *args): return join(self.dir, self.branch(*args)) + + @property + def buildsystem(self): + return self.cfg['buildsystem'] + + def set_buildsystem(self, buildsystem): + self.cfg['buildsystem'] = buildsystem + + @property + def builder(self): + return BuildSystemFactory(self.buildsystem, self) diff --git a/modules/sourceball.py b/modules/sourceball.py index 4940d4b..a1f8779 100644 --- a/modules/sourceball.py +++ b/modules/sourceball.py @@ -27,7 +27,6 @@ from subprocess import Popen, PIPE from tempfile import mkdtemp from base.base import log -from base.dirfactory import DirFactory from base.exceptions import ExecutionException from base.util import pwd, copy, move, base_dir, log_file, rm from base.vars import DIFF_EXCLUDES_FILE |