From 63fe2783e7ff50a9dfded18d42badbf6a1cf75de Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Fri, 4 Jul 2008 00:55:07 +0200 Subject: Change from (sh|run)-(src|...) to --srcdir etc. --- TODO | 5 ++--- src/nbblib/commands.py | 58 +++++++++++++++++++++----------------------------- src/nbblib/main.py | 39 ++++++++++++++++----------------- test/nbb-runsh.at | 30 ++++++++++++++++---------- 4 files changed, 63 insertions(+), 69 deletions(-) diff --git a/TODO b/TODO index 73a5f3e..ec997e7 100644 --- a/TODO +++ b/TODO @@ -31,12 +31,11 @@ TODO: (Large list) * Bash syntax completion for that user interface. * Man page or something similar. Generate from help texts? * Command aliases: - run -> run-build - sh -> sh-build make -> build (for automake, or similar mapping) + * Test sh command like run command. DONE: - * Implement *-sh and *-run commands. + * Implement sh and run commands. * supports execution of user commands in source, build, install dirs * Do not move command objects to plugin detection framework (bad idea!) * Find or implement @abstractmethod decorator. diff --git a/src/nbblib/commands.py b/src/nbblib/commands.py index 3f8e4fd..126500b 100644 --- a/src/nbblib/commands.py +++ b/src/nbblib/commands.py @@ -310,51 +310,41 @@ class MakeCommand(SourceClassCommand): class GeneralRunCommand(SourceClassCommand): """Run general command in some branch specific dir - Non-abstract derived classes MUST define run_in as one of - ['srcdir', 'builddir', 'installdir']. """ - name = None - summary = 'run some command in some dir' + name = 'run' + summary = 'run some command in branch specific dir' validate_args = Command.validate_args_any - def get_run_in_dir(self): - return { - 'srcdir': self.bs_sourcetree.config.srcdir, - 'builddir': self.bs_sourcetree.config.builddir, - 'installdir': self.bs_sourcetree.config.installdir, - }[self.run_in] + def __init__(self, context, *args, **kwargs): + super(GeneralRunCommand, self).__init__(context, *args, **kwargs) + self.rundir = None + self.run_in = 'builddir' + if len(self.args): + if self.args[0] == '--srcdir': + self.args = self.args[1:] + self.rundir = self.bs_sourcetree.config.srcdir + self.run_in = 'srcdir' + elif self.args[0] == '--installdir': + self.args = self.args[1:] + self.rundir = self.bs_sourcetree.config.installdir + self.run_in = 'installdir' + elif self.args[0] == '--builddir': + self.args = self.args[1:] + if not self.rundir: + self.rundir = self.bs_sourcetree.config.builddir def chdir(self): - rundir = self.get_run_in_dir() - if os.path.exists(rundir): - os.chdir(rundir) + if os.path.exists(self.rundir): + os.chdir(self.rundir) else: raise RuntimeError("The %s directory %s does not exist" - % (self.run_in, repr(rundir))) + % (self.run_in, repr(self.rundir))) def run(self): self.chdir() progutils.prog_run(list(self.args), self.context) -class RunSrcCommand(GeneralRunCommand): - name = 'run-src' - summary = 'run given command in source dir' - run_in = 'srcdir' - - -class RunBuildCommand(GeneralRunCommand): - name = 'run-build' - summary = 'run given command in build dir' - run_in = 'builddir' - - -class RunInstallCommand(GeneralRunCommand): - name = 'run-install' - summary = 'run given command in install dir' - run_in = 'installdir' - - class GeneralShellCommand(GeneralRunCommand): - name = None - summary = 'run shell in some dir' + name = 'sh' + summary = 'run shell in branch specific dir' def get_shell_prompt(self): return r",--[Ctrl-d or 'exit' to quit this %s shell for branch '%s']--\n| <%s %s> %s\n\`--[\u@\h \W]\$ " \ % (self.context.prog, self.vcs_sourcetree.branch_name, diff --git a/src/nbblib/main.py b/src/nbblib/main.py index 5a7386e..8798608 100644 --- a/src/nbblib/main.py +++ b/src/nbblib/main.py @@ -17,7 +17,7 @@ Features: * does out-of-source-tree builds (in-source-tree-builds unsupported) * direct support for automake/autoconf based build systems -TBD: Command line interface: +Command line interface (implemeted): Run default build commands: $ %(prog)s [general options] init [command specific options] @@ -25,6 +25,23 @@ TBD: Command line interface: $ %(prog)s [general options] build [command specific options] $ %(prog)s [general options] install [command specific options] + Get/set config: + $ %(prog)s [general options] config srcdir + $ %(prog)s [general options] config builddir [] + $ %(prog)s [general options] config installdir [] + + Start an interactive shell in either of the three directories: + $ %(prog)s [general options] sh --srcdir [command specific options] + $ %(prog)s [general options] sh [--builddir] [command specific options] + $ %(prog)s [general options] sh --installdir [command specific options] + + Run command in either of the three directories: + $ %(prog)s [general options] run --srcdir [...] + $ %(prog)s [general options] run [--builddir] [...] + $ %(prog)s [general options] run --installdir [...] + +TBD: Command line interface: + Run cleanup commands: $ %(prog)s [general options] purge [command specific options] Command specific options: @@ -34,26 +51,6 @@ TBD: Command line interface: $ %(prog)s [general options] purge --all # or that TBD: 'make clean', 'make distclean' and similar stuff? - Get/set config: - $ %(prog)s [general options] config srcdir - $ %(prog)s [general options] config builddir [] - $ %(prog)s [general options] config installdir [] - - Start an interactive shell in either of the three directories: - $ %(prog)s [general options] src-sh [command specific options] - $ %(prog)s [general options] build-sh [command specific options] - $ %(prog)s [general options] install-sh [command specific options] - - Run command in builddir: - $ %(prog)s [general options] run [...] - $ %(prog)s [general options] run [command specific options... <-->] ... - - (Not sure about these) - Run a non-interactive shell command in either of the three directories: - $ %(prog)s [general options] src-sh [command specific options] ... - $ %(prog)s [general options] build-sh [command specific options] ... - $ %(prog)s [general options] install-sh [command specific options] - Global options: -h --help Print this help text diff --git a/test/nbb-runsh.at b/test/nbb-runsh.at index 67a4493..1b89da3 100644 --- a/test/nbb-runsh.at +++ b/test/nbb-runsh.at @@ -7,69 +7,77 @@ dnl =================================================================== dnl Stuff to test: dnl - (srcdir|builddir|installdir) (do|do not) exist -dnl - sh with simple shell script works dnl - run with simple shell script works +dnl - sh with simple shell script works dnl =================================================================== AT_SETUP([nbb run-src]) -AT_KEYWORDS([nbb runsh run-src]) +AT_KEYWORDS([nbb runsh run srcdir]) AT_WRAP_GIT_AM([dnl AT_CHECK([dnl echo "$PWD/test.dir RUN: @<:@'pwd'@:>@ in $PWD/test.dir" > expout -cd test.dir && AT_NBB run-src pwd], [0], [expout]) +cd test.dir && AT_NBB run --srcdir pwd], [0], [expout]) ]) AT_CLEANUP() dnl =================================================================== AT_SETUP([nbb run-build: non-existing builddir]) -AT_KEYWORDS([nbb runsh run-build]) +AT_KEYWORDS([nbb runsh run builddir]) AT_WRAP_GIT_AM([dnl AT_CHECK([dnl echo "ERROR: The builddir directory '$PWD/test.dir/_build/master' does not exist" > experr -cd test.dir && AT_NBB run-build pwd], [1], [], [experr]) +cd test.dir && AT_NBB run --builddir pwd], [1], [], [experr]) +AT_CHECK([dnl +echo "ERROR: The builddir directory '$PWD/test.dir/_build/master' does not exist" > experr +cd test.dir && AT_NBB run pwd], [1], [], [experr]) ]) AT_CLEANUP() dnl =================================================================== AT_SETUP([nbb run-install: non-existing installdir]) -AT_KEYWORDS([nbb runsh run-install]) +AT_KEYWORDS([nbb runsh run installdir]) AT_WRAP_GIT_AM([dnl AT_CHECK([dnl echo "ERROR: The installdir directory '$PWD/test.dir/_install/master' does not exist" > experr -cd test.dir && AT_NBB run-install pwd], [1], [], [experr]) +cd test.dir && AT_NBB run --installdir pwd], [1], [], [experr]) ]) AT_CLEANUP() dnl =================================================================== AT_SETUP([nbb run-build: after build]) -AT_KEYWORDS([nbb runsh run-build]) +AT_KEYWORDS([nbb runsh run builddir]) AT_WRAP_GIT_AM([dnl AT_CHECK([cd test.dir && AT_NBB build], [0], [ignore], [ignore]) AT_CHECK([dnl echo "$PWD/test.dir/_build/master RUN: @<:@'pwd'@:>@ in $PWD/test.dir/_build/master" > expout -cd test.dir && AT_NBB run-build pwd], [0], [expout]) +cd test.dir && AT_NBB run --builddir pwd], [0], [expout]) +AT_CHECK([dnl +echo "$PWD/test.dir/_build/master +RUN: @<:@'pwd'@:>@ + in $PWD/test.dir/_build/master" > expout +cd test.dir && AT_NBB run pwd], [0], [expout]) ]) AT_CLEANUP() dnl =================================================================== AT_SETUP([nbb run-install: after install]) -AT_KEYWORDS([nbb runsh run-install]) +AT_KEYWORDS([nbb runsh run installdir]) AT_WRAP_GIT_AM([dnl AT_CHECK([cd test.dir && AT_NBB install], [0], [ignore], [ignore]) AT_CHECK([dnl echo "$PWD/test.dir/_install/master RUN: @<:@'pwd'@:>@ in $PWD/test.dir/_install/master" > expout -cd test.dir && AT_NBB run-install pwd], [0], [expout]) +cd test.dir && AT_NBB run --installdir pwd], [0], [expout]) ]) AT_CLEANUP() -- cgit