diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-06-23 01:46:32 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-07-15 12:28:52 +0200 |
commit | 41a34022fc7ee1831d20d5e13c459c33fc001732 (patch) | |
tree | 510faa9b313fb6df6c50c09638a833fe62515eb7 /src/nbblib/bs.py | |
parent | 62819016f187acd945fad5b77efde78f88235555 (diff) | |
download | nbb-41a34022fc7ee1831d20d5e13c459c33fc001732.tar.gz nbb-41a34022fc7ee1831d20d5e13c459c33fc001732.tar.xz nbb-41a34022fc7ee1831d20d5e13c459c33fc001732.zip |
Rename nbb/ subdir to src/
Diffstat (limited to 'src/nbblib/bs.py')
-rw-r--r-- | src/nbblib/bs.py | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/nbblib/bs.py b/src/nbblib/bs.py new file mode 100644 index 0000000..cb498cb --- /dev/null +++ b/src/nbblib/bs.py @@ -0,0 +1,126 @@ +######################################################################## +# Buildsystem Source Tree plugins +######################################################################## + + +import os +from nbblib.plugins import * +from nbblib.progutils import * + + +class NotABSSourceTree(Exception): + def __init__(self, vcs_tree): + super(NotABSSourceTree, self).__init__() + self.vcs_tree = vcs_tree + def __str__(self): + return ("Source tree build system type for '%s' not detected" + % (self.vcs_tree,)) + + +class AmbigousBSSource(Exception): + def __init__(self, srcdir, matches): + super(AmbigousBSSource, self).__init__() + self.srcdir = srcdir + self.matches = matches + def __str__(self): + fmt = " %-9s %s" + def strmatch(m): + return fmt % (m.name, m.tree_root()) + alist = [fmt % ('VCS Type', 'Source tree root')] + alist.extend(map(strmatch, self.matches)) + return ("More than one source tree VCS type detected for '%s':\n#%s" + % (self.srcdir, '\n '.join(alist))) + + +class BSSourceTree(object): + __metaclass__ = GenericPluginMeta + + def __init__(self, context): + super(BSSourceTree, self).__init__() + self.context = context + + @classmethod + def detect(cls, vcs_tree, context): + """Find BS tree type and return it""" + if len(BSSourceTree.plugins) < 1: + raise "No BS source tree classes registered" + matches = PluginDict() + for key, klass in BSSourceTree.plugins.items(): + try: + t = klass(vcs_tree, context) + if t.tree_root() == vcs_tree.tree_root(): + matches[key] = t + except NotABSSourceTree, e: + pass + if len(matches) > 1: + raise ("More than one source tree BS type detected for '%s': %s" + % (vcs_tree, ", ".join(map(lambda x:str(x), matches)))) + elif len(matches) < 1: + raise NotABSSourceTree(vcs_tree) + return matches[matches.keys()[0]] + + def __str__(self): + return "BS-Source-Tree(%s, %s)" % (self.name, + repr(self.tree_root())) + + # Abstract methods + def tree_root(self): raise NotImplementedError() + def init(self): raise NotImplementedError() + def configure(self): raise NotImplementedError() + def build(self): raise NotImplementedError() + def install(self): raise NotImplementedError() + + +class AutomakeSourceTree(BSSourceTree): + name = 'automake' + def __init__(self, vcs_tree, context): + super(AutomakeSourceTree, self).__init__(context) + srcdir = vcs_tree.tree_root() + self.config = vcs_tree.config + flag = False + for f in [ os.path.join(srcdir, 'configure.ac'), + os.path.join(srcdir, 'configure.in'), + ]: + if os.path.exists(f): + flag = True + break + if not flag: + raise NotABSSourceTree(vcs_tree) + + def tree_root(self): + return self.config.srcdir + + def init(self): + """'autoreconf'""" + prog_run(["autoreconf", "-v", "-i", "-s", self.config.srcdir], + self.context) + + def configure(self): + """'configure --prefix'""" + builddir = self.config.builddir + if not os.path.exists(builddir): os.makedirs(builddir) + if not os.path.exists(os.path.join(builddir, 'configure')): + self.init + os.chdir(builddir) + prog_run(["%s/configure" % self.config.srcdir, + "--prefix=%s" % self.config.installdir + ], self.context) + + def build(self): + """'make'""" + builddir = self.config.builddir + if not os.path.exists(os.path.join(builddir, 'config.status')): + self.configure() + os.chdir(builddir) + prog_run(["make", ], self.context) + + def install(self): + """'make install'""" + builddir = self.config.builddir + if not os.path.exists(os.path.join(builddir, 'config.status')): + self.configure() + os.chdir(builddir) + prog_run(["make", "install", "INSTALL=/usr/bin/install -p"], + self.context) + + |