From d3d01a3237b1767f61953e34879dffd16667b769 Mon Sep 17 00:00:00 2001 From: "Yaakov M. Nemoy" Date: Sun, 18 Jan 2009 22:21:05 -0500 Subject: Modifies factories, adds a BuildSystemFactory BSFactory, oh yeah! --- base/dirfactory.py | 67 --------------------------------------- base/factories.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ modules/build.py | 2 +- modules/buildsystem.py | 15 +++++++++ modules/cabal.py | 9 ++---- modules/darcs.py | 7 ----- modules/directory.py | 6 ++-- modules/haskellport.py | 2 +- modules/mock.py | 2 +- modules/package.py | 2 +- modules/packagesource.py | 13 +++++++- modules/sourceball.py | 1 - 12 files changed, 117 insertions(+), 90 deletions(-) delete mode 100644 base/dirfactory.py create mode 100644 base/factories.py diff --git a/base/dirfactory.py b/base/dirfactory.py deleted file mode 100644 index 57d66db..0000000 --- a/base/dirfactory.py +++ /dev/null @@ -1,67 +0,0 @@ -# Fedora Developer Shell -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Library General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# Authors: Yaakov M. Nemoy -# - -from __future__ import with_statement - -from configobj import ConfigObj -from os import getcwd -from os.path import abspath, exists - -from util import pwd, log -from exceptions import ExecutionException - -directory_type = dict() - -def register(cls, name): - global directory_type - directory_type[name] = cls - -class DirFactory(object): - '''creates a new object of type defined by a directory's .devshell file''' - def __new__(cls, name=None): - if not name: - log.debug('no name with dirfactory') - dir = getcwd() - type = whatis_sysdir(dir) - else: - log.debug('dirfactory.new with name ' + name) - dir = abspath(name) - if not exists(dir): - type = 'directory' - else: - type = whatis_sysdir(dir) - try: - new_cls = directory_type[type] - except KeyError, e: - raise ExecutionException(e, 'the directory type %s is not supported by this installation of fedora-deveshell' % type.capitalize()) - foo = new_cls.__new__(new_cls, name) - foo.__init__(name) - return foo - -def whatis_sysdir(dir): - ''' given a dir, determine it's type''' - with pwd(dir): - cfg = ConfigObj('.devshell') - try: - type = cfg['type'] - log.debug('is type ' + type) - return type - except KeyError, e: - return 'directory' - -__all__ = ['DirFactory', 'register'] diff --git a/base/factories.py b/base/factories.py new file mode 100644 index 0000000..98022fe --- /dev/null +++ b/base/factories.py @@ -0,0 +1,81 @@ +# Fedora Developer Shell +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Authors: Yaakov M. Nemoy +# + +from __future__ import with_statement + +from configobj import ConfigObj +from os import getcwd +from os.path import abspath, exists + +from util import pwd, log +from exceptions import ExecutionException + +directory_type = dict() + +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): + if not name: + log.debug('no name with dirfactory') + dir = getcwd() + type = whatis_sysdir(dir) + else: + log.debug('dirfactory.new with name ' + name) + dir = abspath(name) + if not exists(dir): + type = 'directory' + else: + type = whatis_sysdir(dir) + try: + new_cls = directory_type[type] + except KeyError, e: + raise ExecutionException(e, 'the directory type %s is not supported by this installation of fedora-deveshell' % type.capitalize()) + foo = new_cls.__new__(new_cls, name) + foo.__init__(name) + return foo + +def whatis_sysdir(dir): + ''' given a dir, determine it's type''' + with pwd(dir): + cfg = ConfigObj('.devshell') + try: + type = cfg['type'] + log.debug('is type ' + type) + return type + except KeyError, e: + return 'directory' + +__all__ = ['DirFactory', 'register'] 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 -- cgit