summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2008-07-04 00:11:21 +0200
committerHans Ulrich Niedermann <hun@n-dimensional.de>2008-07-15 12:28:56 +0200
commitbf133a4636cb6d1513e0b1d88a4ebb2e0a56a4eb (patch)
tree7736c274285bce3f73a94e146a74e018f8539809
parent5d325e60db5e764422ed22a48a15931134eeb7c7 (diff)
downloadnbb-bf133a4636cb6d1513e0b1d88a4ebb2e0a56a4eb.tar.gz
nbb-bf133a4636cb6d1513e0b1d88a4ebb2e0a56a4eb.tar.xz
nbb-bf133a4636cb6d1513e0b1d88a4ebb2e0a56a4eb.zip
Catch non-existing dirs in (sh|run)-* commands
Catch and report properly.
-rw-r--r--src/nbblib/commands.py11
-rw-r--r--src/nbblib/main.py4
2 files changed, 13 insertions, 2 deletions
diff --git a/src/nbblib/commands.py b/src/nbblib/commands.py
index bf8c6b5..c250cb1 100644
--- a/src/nbblib/commands.py
+++ b/src/nbblib/commands.py
@@ -317,8 +317,15 @@ class GeneralRunCommand(SourceClassCommand):
'builddir': self.bs_sourcetree.config.builddir,
'installdir': self.bs_sourcetree.config.installdir,
}[self.run_in]
+ def chdir(self):
+ rundir = self.get_run_in_dir()
+ if os.path.exists(rundir):
+ os.chdir(rundir)
+ else:
+ raise RuntimeError("The %s directory %s does not exist"
+ % (self.run_in, repr(rundir)))
def run(self):
- os.chdir(self.get_run_in_dir())
+ self.chdir()
progutils.prog_run(list(self.args), self.context)
@@ -348,7 +355,7 @@ class GeneralShellCommand(GeneralRunCommand):
% (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())
+ self.chdir()
# FIXME: Allow using $SHELL or similar.
progutils.prog_run(['sh'] + list(self.args), self.context,
env_update = {'PS1': self.get_shell_prompt()})
diff --git a/src/nbblib/main.py b/src/nbblib/main.py
index 22c93e3..5a7386e 100644
--- a/src/nbblib/main.py
+++ b/src/nbblib/main.py
@@ -268,6 +268,10 @@ def cmdmain(argv):
logging.error(e)
logging.shutdown()
sys.exit(1)
+ except RuntimeError, e:
+ logging.error(e)
+ logging.shutdown()
+ sys.exit(1)
except progutils.ProgramRunError, e:
logging.error(e)
logging.shutdown()