From 4f6b2987ed33db74824b4cb2f91032f03ec7d26a Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Wed, 25 Jun 2008 16:42:38 +0200 Subject: Converging plugin detect() methods --- src/nbblib/bs.py | 8 +++++--- src/nbblib/vcs.py | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nbblib/bs.py b/src/nbblib/bs.py index b325355..aff1834 100644 --- a/src/nbblib/bs.py +++ b/src/nbblib/bs.py @@ -42,19 +42,21 @@ class BSSourceTree(object): @classmethod def detect(cls, vcs_tree, context): """Find BS tree type and return it""" - if len(BSSourceTree.plugins) < 1: + if len(cls.plugins) < 1: raise NoPluginsRegistered(cls) + # print "CLASS", cls matches = PluginDict() - for key, klass in BSSourceTree.plugins.iteritems(): + for key, klass in cls.plugins.iteritems(): try: t = klass(vcs_tree, context) if t.tree_root() == vcs_tree.tree_root(): + # print "KLASS", klass 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)))) + % (vcs_tree, ", ".join([str(x) for x in matches]))) elif len(matches) < 1: raise NotABSSourceTree(vcs_tree) return matches[matches.keys()[0]] diff --git a/src/nbblib/vcs.py b/src/nbblib/vcs.py index a5df8c9..38d04b5 100644 --- a/src/nbblib/vcs.py +++ b/src/nbblib/vcs.py @@ -45,8 +45,8 @@ class AmbigousVCSource(Exception): fmt = " %-9s %-15s %s" def strmatch(m): return fmt % (m.name, m.branch_name(), m.tree_root()) - alist = ([fmt % ('VCS Type', 'Branch Name', 'Source tree root')] - + map(strmatch, self.matches)) + alist = ([fmt % ('VCS Type', 'Branch Name', 'Source tree root')] + + [fmt % (m.name, m.branch_name(), m.tree_root()) for m in self.matches]) return ("More than one source tree VCS type detected for '%s':\n#%s" % (self.srcdir, '\n '.join(alist))) @@ -72,13 +72,15 @@ class VCSourceTree(object): @classmethod def detect(cls, srcdir, context): """Detect VCS tree type and return object representing it""" - if len(VCSourceTree.plugins) < 1: + if len(cls.plugins) < 1: raise NoPluginsRegistered(cls) + # print "CLASS", cls matches = PluginDict() - for key, klass in VCSourceTree.plugins.iteritems(): + for key, klass in cls.plugins.iteritems(): try: t = klass(srcdir, context) if t.tree_root() == srcdir: + # print "KLASS", klass matches[key] = t except NotAVCSourceTree, e: pass -- cgit