summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-03 15:41:24 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-03 15:41:24 -0500
commit36953f9c563700d4ef67149c2c13c1df70b02c96 (patch)
tree06c39559b2e66f6467f95fcdafc88d60d47d78b3 /modules
parente427d02a7693c395d26c03f6a12a09ca504009bc (diff)
downloadfedora-devshell-36953f9c563700d4ef67149c2c13c1df70b02c96.tar.gz
fedora-devshell-36953f9c563700d4ef67149c2c13c1df70b02c96.tar.xz
fedora-devshell-36953f9c563700d4ef67149c2c13c1df70b02c96.zip
Add directory factory autodetect powers
Diffstat (limited to 'modules')
-rw-r--r--modules/cabal.py62
-rw-r--r--modules/directory.py9
-rw-r--r--modules/dirfactory.py70
-rw-r--r--modules/package.py2
-rw-r--r--modules/revisioncontrol.py23
-rw-r--r--modules/sourceball.py8
6 files changed, 138 insertions, 36 deletions
diff --git a/modules/cabal.py b/modules/cabal.py
index 0fd0e94..ecb0f6b 100644
--- a/modules/cabal.py
+++ b/modules/cabal.py
@@ -32,6 +32,7 @@ from base.exceptions import ExecutionException
from base.util import pwd, one
from base.vars import orig_src_dir, haskell_compiler
+from modules.dirfactory import DirFactory
from modules.sourceball import SourceBall
class Cabal(Module):
@@ -39,7 +40,7 @@ class Cabal(Module):
self.name = name
self.root = expanduser(root)
with pwd(self.root):
- self.package = SourceBall(name)
+ self.package = DirFactory(name)
self.original = orig_src_dir
self.compiler = haskell_compiler
@@ -48,65 +49,66 @@ class Cabal(Module):
with pwd(self.root):
self.package.add_sourceball(tarball)
- def find_setup(self, original=False):
+ def find_setup(self, orig=''):
setup_re = compile("Setup\.l?hs")
- with pwd(self.source_dir(original)):
- setup_f = one(listdir(getcwd()), setup_re.search)
- log.debug(setup_f)
- return setup_f
+ return one(listdir(getcwd()), setup_re.search)
- def compile_setup(self, original=False):
- with pwd(self.pkg.code_dir):
+ def compile_setup(self, orig=''):
+ log.debug('code_dir is ' + self.package.code_dir)
+ with pwd(self.package.code_dir):
with file('ghc.log', 'a') as ghc_out:
- with pwd(self.source_dir(original)):
- setup_f = self.find_setup(original)
+ log.debug('ghc.log file is ' + str(ghc_out))
+ log.debug('source_dir is ' + self.package.source_dir(orig))
+ with pwd(self.package.source_dir(orig)):
+ setup_f = self.find_setup(orig)
p = Popen([self.compiler, '--make', setup_f],
stdout = ghc_out, stderr = ghc_out)
log.info('Building %s, please wait...' % setup_f)
p.wait()
- def configure(self, target='home', original=False):
+ def configure(self, target='home', orig=''):
user = True if target == 'home' else False
- self.compile_setup(original)
- with pwd(self.pkg.code_dir):
+ self.compile_setup(orig)
+ with pwd(self.package.code_dir):
with file('cabal.log', 'a') as cabal_out:
- with pwd(self.source_dir(original)):
+ log.debug('source_dir is ' + self.package.source_dir(orig))
+ with pwd(self.package.source_dir(orig)):
args = [abspath('Setup'), 'configure'] + \
(['--user', '--prefix=' + expanduser('~')] if user else [])
p = Popen(args, stdout=cabal_out, stderr=cabal_out)
log.info('Configuring %s, please wait...' % self.name)
p.wait()
- def build(self, original=False):
+ def build(self, orig=''):
'''This is not safe to run on an unconfigured source dir'''
- self.compile_setup(original)
- with pwd(self.pkg.code_dir):
+ self.compile_setup(orig)
+ with pwd(self.package.code_dir):
with file('cabal.log', 'a') as cabal_out:
- with pwd(self.source_dir(original)):
+ with pwd(self.package.source_dir(orig)):
args = [abspath('Setup'), 'build']
p = Popen(args, stdout=cabal_out, stderr=cabal_out)
log.info('Building %s, please wait...' % self.name)
p.wait()
- def install(self, original=False):
+ def install(self, orig=''):
'''This is not safe to run on an unconfigured source dir'''
- self.compile_setup(original)
- with pwd(self.pkg.code_dir):
+ self.compile_setup(orig)
+ with pwd(self.package.code_dir):
with file('cabal.log', 'a') as cabal_out:
- with pwd(self.source_dir(original)):
+ with pwd(self.package.source_dir(orig)):
args = [abspath('Setup'), 'install']
p = Popen(args, stdout=cabal_out, stderr=cabal_out)
log.info('Building %s, please wait...' % self.name)
p.wait()
- def install_source(self, target='home', original=False):
- self.configure(target, original)
- self.build(original)
- self.install(original)
+ def install_source(self, target='home', orig=''):
+ self.configure(target, orig)
+ self.build(orig)
+ self.install(orig)
def install_sourceball(self, tarball, target='home'):
self.copy_in(tarball)
- self.install_source(target, False)
+ self.install_source(target, '')
def get_from_hackage(self, pkg, ver):
sb_file = self.hackage_url(pkg, ver)
@@ -118,13 +120,13 @@ class Cabal(Module):
def install_from_hackage(self, pkg, ver, target='home'):
self.get_from_hackage(pkg, ver)
- self.install_source(target, False)
+ self.install_source(target, '')
def install_latest(self, pkg, target='home'):
self.get_latest(pkg)
- self.install_source(target, False)
+ self.install_source(target, '')
- def source_dir(self, original=False):
+ def source_dir(self, *args):
with pwd(self.package.code_dir):
return abspath(self.package.cfg['source'] + (self.orig_src_dir if original else ""))
diff --git a/modules/directory.py b/modules/directory.py
index ed27eeb..6d7f432 100644
--- a/modules/directory.py
+++ b/modules/directory.py
@@ -20,14 +20,14 @@
from __future__ import with_statement
from configobj import ConfigObj
-from os import makedirs, getcwd
-from os.path import abspath, join, split, splitext, basename, exists
+from os import makedirs, getcwd, listdir
+from os.path import abspath, join, split, splitext, basename, exists, dirname
from base.base import log
from base.module import Module
from base.util import pwd
-
+
class Directory(Module):
_type = 'directory'
def __init__(self, name=None):
@@ -35,11 +35,10 @@ class Directory(Module):
log.debug('no name with package')
cwd = getcwd()
log.debug(split(cwd))
- if self.is_dir_pkg(cwd):
+ if self.is_sysdir_dir(cwd):
self.load_dir(cwd)
else:
self.make_dir(cwd)
- #TODO: detect name somehow
else:
log.debug('package.init with name ' + name)
dir = abspath(name)
diff --git a/modules/dirfactory.py b/modules/dirfactory.py
new file mode 100644
index 0000000..3665a89
--- /dev/null
+++ b/modules/dirfactory.py
@@ -0,0 +1,70 @@
+# 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 <ynemoy@redhat.com>
+#
+
+from __future__ import with_statement
+
+from configobj import ConfigObj
+from inspect import isclass
+from os import getcwd
+from os.path import abspath, exists
+
+from base.util import pwd, log
+from base.module import Module
+from modules.package import Package
+from modules.directory import Directory
+from modules.revisioncontrol import RevisionControl
+from modules.sourceball import SourceBall
+
+# TODO: i'm jumping through bureaucrautic hoops right now.
+# Don't program at 3am kids, it's harmful to your sanity
+foo = []
+for x,y in globals().copy().iteritems():
+ foo.append([x,y])
+foo = dict(foo)
+dirs = dict([[key.lower(), val] for key, val in foo.iteritems() if isclass(val) and issubclass(val, Directory)])
+
+class DirFactory(Module):
+ 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)
+ 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):
+ with pwd(dir):
+ cfg = ConfigObj('.devshell')
+ try:
+ type = cfg['type']
+ log.debug('is type ' + type)
+ return type
+ except KeyError, e:
+ return 'directory'
diff --git a/modules/package.py b/modules/package.py
index 4efb186..8d61091 100644
--- a/modules/package.py
+++ b/modules/package.py
@@ -58,5 +58,7 @@ class Package(Directory):
ver, rel = ver_rel(self.spec_file, profile.dist_defines())
return '%s-%s-%s.src.rpm' % (self.name, ver, rel)
+ def source_dir(self, *args):
+ raise NotImplementedError
__all__ = ['Package']
diff --git a/modules/revisioncontrol.py b/modules/revisioncontrol.py
new file mode 100644
index 0000000..ef43424
--- /dev/null
+++ b/modules/revisioncontrol.py
@@ -0,0 +1,23 @@
+# 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 <ynemoy@redhat.com>
+#
+
+from modules.package import Package
+
+class RevisionControl(Package):
+
+ pass
diff --git a/modules/sourceball.py b/modules/sourceball.py
index 5a840d3..3008e40 100644
--- a/modules/sourceball.py
+++ b/modules/sourceball.py
@@ -30,8 +30,15 @@ from base.util import pwd, copy
from modules.package import Package
class SourceBall(Package):
+ _type = 'sourceball'
def orig_dir(self, dir):
return dir + '_orig'
+
+ def source_dir(self, *args):
+ if args[0] == 'orig':
+ return self.orig_dir(self.cfg['source'])
+ else:
+ return self.cfg['source']
def add_sourceball(self, sourceball_name, extract_dir=None):
log.debug('addincg sourceball with code_dir ' + self.code_dir)
@@ -49,7 +56,6 @@ class SourceBall(Package):
log.debug('config is of ' + str(self.cfg))
self.cfg['source'] = extract_dir
log.debug('cfg[\'source\'] is ' + self.cfg['source'])
- log.debug('set source')
orig_extract_dir = self.orig_dir(extract_dir)
sourceball.extractall()
copytree(abspath(extract_dir), abspath(orig_extract_dir))