diff options
Diffstat (limited to 'nbb/nbblib/bs.py')
-rw-r--r-- | nbb/nbblib/bs.py | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/nbb/nbblib/bs.py b/nbb/nbblib/bs.py new file mode 100644 index 0000000..a254c95 --- /dev/null +++ b/nbb/nbblib/bs.py @@ -0,0 +1,113 @@ +######################################################################## +# Buildsystem Source Tree plugins +######################################################################## + + +import os +from nbblib.plugins 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')] + 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) + os.chdir(builddir) + prog_run(["%s/configure" % self.config.srcdir, + "--prefix=%s" % self.config.installdir + ], self.context) + + def build(self): + """'make'""" + os.chdir(self.config.builddir) + prog_run(["make", ], self.context) + + def install(self): + """'make install'""" + os.chdir(self.config.builddir) + prog_run(["make", "install", "INSTALL=/usr/bin/install -p"], self.context) + + |