diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | nbb/nbblib/__init__.in | 135 | ||||
-rw-r--r-- | test/Makefile.am | 1 | ||||
-rw-r--r-- | test/nbb-commands.at | 44 | ||||
-rw-r--r-- | test/nbb-config.at | 74 |
6 files changed, 191 insertions, 66 deletions
diff --git a/Makefile.am b/Makefile.am index 48f5e6d..52f61f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -80,7 +80,7 @@ tag: UPLOAD_DIR = upload-dir ALL_UPLOAD_FILES = $(UPLOAD_FILES) $(distdir).tar.bz2 -upload: $(UPLOAD_FILES) dist tag +upload: $(UPLOAD_FILES) dist rm -rf "$(UPLOAD_DIR)" mkdir -p "$(UPLOAD_DIR)" for f in $(ALL_UPLOAD_FILES); do \ @@ -2,6 +2,7 @@ nbb 1.20.x * Automatically call autoreconf for GNU make users. * Implement 'nbb help <command>'. * Implement global nbb options --vcs, --build-system, --dry-run. + * Implement 'nbb config <option> [<new-value>]'. * Rename python module from nbb_lib.py to nbblib/__init__.py. * Miscellaneous build fixes related to move to standalone nbb. diff --git a/nbb/nbblib/__init__.in b/nbb/nbblib/__init__.in index 68ff03d..16a6896 100644 --- a/nbb/nbblib/__init__.in +++ b/nbb/nbblib/__init__.in @@ -80,6 +80,8 @@ import urlparse # Used to make sure nbb_lib and nbb fit together PACKAGE_VERSION = "@PACKAGE_VERSION@" +GIT_CONFIG_PREFIX = 'nbb' + ######################################################################## # Utility functions @@ -111,6 +113,15 @@ def prog_stdout(call_list): return stdout.strip() +def prog_retstd(call_list): + """Run program and return stdout (similar to shell backticks)""" + p = subprocess.Popen(call_list, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = p.communicate(input=None) + return (p.returncode, stdout.strip(), stderr.strip()) + + class ProgramRunError(Exception): """A program run returns a retcode != 0""" def __init__(self, call_list, retcode, cwd=None): @@ -144,6 +155,7 @@ class AbstractConfig(object): """Return static config until we implement real config reading""" def __init__(self, srcdir, nick): + super(AbstractConfig, self).__init__() self._srcdir = srcdir self._nick = nick @@ -162,6 +174,7 @@ class AbstractConfig(object): class CommandLineError(Exception): def __init__(self, message, *args): + super(CommandLineError, self).__init__() if args: self.msg = message % args else: @@ -266,21 +279,15 @@ class VCSourceTree(object): if len(VCSourceTree.plugins) < 1: raise "No VC source tree classes registered" matches = PluginDict() - print "VCSourceTree.detect", VCSourceTree.plugins - print "srcdir", srcdir for key, klass in VCSourceTree.plugins.items(): - print "key", key - print "klass", klass try: matches[key] = klass(srcdir, context) - print "MATCH:", srcdir except NotAVCSourceTree, e: pass if len(matches) > 1: raise AmbigousAVCSource(srcdir, str(matches.values())) elif len(matches) < 1: raise NotAVCSourceTree(srcdir) - print "Matches:", matches return matches[matches.keys()[0]] def get_config(self): @@ -399,6 +406,46 @@ class HelpCommand(Command): else: assert(False) + +class GitConfig(AbstractConfig): + """""" + + def __init__(self, *args, **kwargs): + super(GitConfig, self).__init__(*args, **kwargs) + + def _itemname(self, item): return '.'.join((GIT_CONFIG_PREFIX, item, )) + def _myreldir(self, rdir): + return os.path.join(self._srcdir, rdir, self._nick) + + def get_builddir(self): + ret, stdout, stderr = prog_retstd(['git', 'config', self._itemname('builddir')]) + assert(stderr == "") + if ret == 0 and stdout: + return self._myreldir(stdout) + else: + return super(GitConfig, self).get_builddir() + + def set_builddir(self, value): + ret, stdout, stderr = prog_retstd(['git', 'config', self._itemname('builddir'), value]) + assert(ret == 0 and stdout == "" and stderr == "") + + builddir = property(get_builddir, set_builddir) + + def get_installdir(self): + ret, stdout, stderr = prog_retstd(['git', 'config', self._itemname('installdir')]) + assert(stderr == "") + if ret == 0 and stdout: + return self._myreldir(stdout) + else: + return super(GitConfig, self).get_installdir() + + def set_installdir(self, value): + ret, stdout, stderr = prog_retstd(['git', 'config', self._itemname('installdir'), value]) + assert(ret == 0 and stdout == "" and stderr == "") + + installdir = property(get_installdir, set_installdir) + + class InternalConfigCommand(Command): name = 'internal-config' summary = 'print internal program configuration' @@ -416,15 +463,17 @@ class SourceClassCommand(Command): srcdir = os.getcwd() absdir = os.path.abspath(srcdir) self.vcs_sourcetree = VCSourceTree.detect(absdir, context) - print "vcs_sourcetree", str(self.vcs_sourcetree) + if context.verbose: + print "vcs_sourcetree", str(self.vcs_sourcetree) assert(self.vcs_sourcetree) cfg = self.vcs_sourcetree.config self.bs_sourcetree = BSSourceTree.detect(self.vcs_sourcetree, context) - print "bs_sourcetree", str(self.bs_sourcetree) - print "CONFIG" - print " ", "srcdir", cfg.srcdir - print " ", "builddir", cfg.builddir - print " ", "installdir", cfg.installdir + if context.verbose: + print "bs_sourcetree", str(self.bs_sourcetree) + print "CONFIG", cfg + print " ", "srcdir", cfg.srcdir + print " ", "builddir", cfg.builddir + print " ", "installdir", cfg.installdir class BuildTestCommand(SourceClassCommand): @@ -437,6 +486,45 @@ class BuildTestCommand(SourceClassCommand): self.bs_sourcetree.install() +class ConfigCommand(SourceClassCommand): + name = 'config' + summary = 'set/get config values' + usage = '(srcdir|builddir|installdir)' + + def validate_args(self, *args, **kwargs): + items = ('srcdir', 'builddir', 'installdir', ) + if len(args) == 0: + raise CommandLineError("'%s' requires at least one parameter (%s)", self.name, + ', '.join(items)) + elif len(args) == 1 and args[0] in items: + pass + elif len(args) == 2 and args[0] in items: + if args[0] in ('srcdir', ): + raise CommandLineError("'%s' command cannot change 'srcdir'", self.name) + else: + pass + else: + raise CommandLineError("'%s' requires less or different parameters", self.name) + + def run(self): + git_get_items = ('builddir', 'installdir', 'srcdir') + git_set_items = ('builddir', 'installdir', ) + if len(self.args) == 1: + if self.args[0] in git_get_items: + print getattr(self.vcs_sourcetree.config, self.args[0]) + else: + assert(False) + elif len(self.args) == 2: + if self.args[0] == 'builddir': + self.vcs_sourcetree.config.builddir = self.args[1] + elif self.args[0] == 'installdir': + self.vcs_sourcetree.config.installdir = self.args[1] + else: + assert(False) + else: + assert(False) + + ######################################################################## # VCS Source Tree plugins ######################################################################## @@ -456,6 +544,10 @@ class GitSourceTree(VCSourceTree): os.chdir(reldir) self.__tree_root = os.getcwd() + def get_config(self): + return GitConfig(self.tree_root(), self.branch_name()) + config = property(get_config) + def tree_root(self): return self.__tree_root @@ -529,8 +621,7 @@ class BSSourceTree(object): 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 "Source tree type for '%s' not detected" % (vcs_tree,) - print "Matches:", matches + raise "Source tree build system type for '%s' not detected" % (vcs_tree,) return matches[matches.keys()[0]] def __str__(self): @@ -661,17 +752,22 @@ class BSProperty(Property): return (value in BSSourceTree.plugins.keys()) -class DryRunProperty(Property): - def __init__(self): - super(DryRunProperty, self).__init__(default=False) +class BoolProperty(Property): + def __init__(self, default=False): + super(BoolProperty, self).__init__(default=default) def isvalid(self, value): return (value in (True, False)) +class DryRunProperty(BoolProperty): + def __init__(self): + super(DryRunProperty, self).__init__(default=False) + class Context(object): vcs = VCSProperty() bs = BSProperty() dry_run = DryRunProperty() + verbose = BoolProperty() def main(argv): @@ -685,7 +781,6 @@ def main(argv): print "Fatal: %(prog)s requires some arguments" % outdict return 2 - verbosity = 0 i = 1 ctx = Context() while i<len(argv): @@ -712,9 +807,7 @@ def main(argv): elif argv[i][:6] == '--vcs=': ctx.vcs = argv[i][6:] elif argv[i] in ('--verbose', ): - verbosity = verbosity + 1 - elif argv[i] in ('--quiet', ): - verbosity = verbosity - 1 + ctx.verbose = True # print "", i, argv[i] i = i + 1 cmd = argv[i] diff --git a/test/Makefile.am b/test/Makefile.am index ee1666c..8a192b2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -6,6 +6,7 @@ DISTCLEANFILES = TESTCASES = TESTCASES += autotest.at TESTCASES += nbb-basic.at +TESTCASES += nbb-config.at # Add more testcases here EXTRA_DIST += $(TESTCASES) diff --git a/test/nbb-commands.at b/test/nbb-commands.at deleted file mode 100644 index 4f045ab..0000000 --- a/test/nbb-commands.at +++ /dev/null @@ -1,44 +0,0 @@ -dnl =================================================================== - -AT_COPYRIGHT([Copyright (C) 2008 Hans Ulrich Niedermann]) -AT_TESTED([nbb]) - -dnl =================================================================== - -AT_SETUP([nbb: git config default defaults]) -AT_KEYWORDS([nbb git config]) -AT_CHECK([mkdir test.git && cd test.git]) -AT_CHECK([cd test.git && git init], [0], -[Initialized empty Git repository in .git/ -]) -echo "$PWD/test.git" > expout -AT_CHECK([cd test.git && nbb config srcdir], [0], [expout]) -echo "$PWD/test.git/_build/_master" > expout -AT_CHECK([cd test.git && nbb config builddir], [0], [expout]) -echo "$PWD/test.git/_install/master" > expout -AT_CHECK([cd test.git && nbb config installdir], [0], [expout]) -AT_CHECK([rm -rf test.git]) -AT_CLEANUP() - -dnl =================================================================== - -AT_SETUP([nbb: bzr config defaults]) -AT_KEYWORDS([nbb bzr config]) -AT_CHECK([mkdir test.bzr && cd test.bzr]) -AT_CHECK([cd test.bzr && bzr init]) -echo "$PWD/test.bzr" > expout -AT_CHECK([cd test.bzr && nbb config srcdir], [0], [expout]) -echo "$PWD/test.bzr/_build" > expout -AT_CHECK([cd test.bzr && nbb config builddir], [0], [expout]) -echo "$PWD/test.bzr/_install" > expout -AT_CHECK([cd test.bzr && nbb config installdir], [0], [expout]) -AT_CHECK([rm -rf test.git]) -AT_CLEANUP() - -dnl =================================================================== - -dnl =================================================================== - -dnl =================================================================== - - diff --git a/test/nbb-config.at b/test/nbb-config.at new file mode 100644 index 0000000..5b09199 --- /dev/null +++ b/test/nbb-config.at @@ -0,0 +1,74 @@ +dnl =================================================================== + +AT_COPYRIGHT([Copyright (C) 2008 Hans Ulrich Niedermann]) +AT_TESTED([nbb]) + +dnl =================================================================== + +AT_SETUP([nbb: git config defaults]) +AT_KEYWORDS([nbb git config]) +AT_CHECK([mkdir test.git && cd test.git]) +AT_CHECK([cd test.git && git init], [0], +[Initialized empty Git repository in .git/ +]) +AT_DATA([test.git/configure.ac], [dnl +AC[_]INIT(nbb-test, 1.2.3, invalid@invalid.invalid) +AC[_]OUTPUT +]) +AT_CHECK([echo "$PWD/test.git" > expout +cd test.git && nbb config srcdir], [0], [expout]) +AT_CHECK([echo "$PWD/test.git/_build/master" > expout +cd test.git && nbb config builddir], [0], [expout]) +AT_CHECK([echo "$PWD/test.git/_install/master" > expout +cd test.git && nbb config installdir], [0], [expout]) +AT_CHECK([rm -rf test.git]) +AT_CLEANUP() + +dnl =================================================================== + +AT_SETUP([nbb: git config set/get]) +AT_KEYWORDS([nbb git config]) +AT_CHECK([mkdir test.git && cd test.git]) +AT_CHECK([cd test.git && git init], [0], +[Initialized empty Git repository in .git/ +]) +AT_DATA([test.git/configure.ac], [dnl +AC[_]INIT(nbb-test, 1.2.3, invalid@invalid.invalid) +AC[_]OUTPUT +]) +AT_CHECK([echo "$PWD/test.git" > expout +cd test.git && nbb config srcdir], [0], [expout]) +AT_CHECK([echo "$PWD/test.git/_build/master" > expout +cd test.git && nbb config builddir], [0], [expout]) +AT_CHECK([cd test.git && nbb config builddir _foo]) +AT_CHECK([echo "$PWD/test.git/_foo/master" > expout +cd test.git && nbb config builddir], [0], [expout]) +AT_CHECK([cd test.git && nbb config builddir _bar]) +AT_CHECK([echo "$PWD/test.git/_bar/master" > expout +cd test.git && nbb config builddir], [0], [expout]) +dnl TBD: --unset or something similar to reset to defaults +AT_CHECK([rm -rf test.git]) +AT_CLEANUP() + +dnl =================================================================== + +dnl AT_SETUP([nbb: bzr config defaults]) +dnl AT_KEYWORDS([nbb bzr config]) +dnl AT_CHECK([mkdir test.bzr && cd test.bzr]) +dnl AT_CHECK([cd test.bzr && bzr init]) +dnl echo "$PWD/test.bzr" > expout +dnl AT_CHECK([cd test.bzr && nbb config srcdir], [0], [expout]) +dnl echo "$PWD/test.bzr/_build" > expout +dnl AT_CHECK([cd test.bzr && nbb config builddir], [0], [expout]) +dnl echo "$PWD/test.bzr/_install" > expout +dnl AT_CHECK([cd test.bzr && nbb config installdir], [0], [expout]) +dnl AT_CHECK([rm -rf test.git]) +dnl AT_CLEANUP() + +dnl =================================================================== + +dnl =================================================================== + +dnl =================================================================== + + |