summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2008-07-03 23:26:07 +0200
committerHans Ulrich Niedermann <hun@n-dimensional.de>2008-07-15 12:28:56 +0200
commitdea1becfe1d9ad4af9d7f928de0596ff40102aa3 (patch)
tree3fc60652b8e695937f5a4aa782518c3db2f44a66
parent5eff502ced858a7d3a4f3b1c4d44b28e83dc92de (diff)
downloadnbb-dea1becfe1d9ad4af9d7f928de0596ff40102aa3.tar.gz
nbb-dea1becfe1d9ad4af9d7f928de0596ff40102aa3.tar.xz
nbb-dea1becfe1d9ad4af9d7f928de0596ff40102aa3.zip
Implement run-* and sh-* commands
-rw-r--r--TODO2
-rw-r--r--src/nbblib/commands.py65
2 files changed, 66 insertions, 1 deletions
diff --git a/TODO b/TODO
index e9ab673..72589c4 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,4 @@
TODO: (to get git-amb equivalent functionality)
- * Implement *-sh and *-run commands.
* Prepare public release:
* Clean up git tags.
* Start new git repo (get rid of old ndim-git-utils stuff).
@@ -34,6 +33,7 @@ TODO: (Large list)
* Man page or something similar. Generate from help texts?
DONE:
+ * Implement *-sh and *-run commands.
* Do not move command objects to plugin detection framework (bad idea!)
* Find or implement @abstractmethod decorator.
* Unify detect() methods.
diff --git a/src/nbblib/commands.py b/src/nbblib/commands.py
index 2e653b6..bf8c6b5 100644
--- a/src/nbblib/commands.py
+++ b/src/nbblib/commands.py
@@ -307,6 +307,71 @@ class MakeCommand(SourceClassCommand):
self.context)
+class GeneralRunCommand(SourceClassCommand):
+ name = None
+ summary = 'run some command in some 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 run(self):
+ os.chdir(self.get_run_in_dir())
+ 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'
+ 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,
+ self.context.prog, self.name, self.get_run_in_dir(), )
+ def run(self):
+ os.chdir(self.get_run_in_dir())
+ # FIXME: Allow using $SHELL or similar.
+ progutils.prog_run(['sh'] + list(self.args), self.context,
+ env_update = {'PS1': self.get_shell_prompt()})
+
+
+class SrcShellCommand(GeneralShellCommand):
+ name = 'sh-src'
+ summary = 'run interactive shell in source dir'
+ run_in = 'srcdir'
+
+
+class BuildShellCommand(GeneralShellCommand):
+ name = 'sh-build'
+ summary = 'run interactive shell in build dir'
+ run_in = 'builddir'
+
+
+class InstallShellCommand(GeneralShellCommand):
+ name = 'sh-install'
+ summary = 'run interactive shell in install dir'
+ run_in = 'installdir'
+
+
class ConfigCommand(SourceClassCommand):
name = 'config'
summary = 'set/get config values'