From bf133a4636cb6d1513e0b1d88a4ebb2e0a56a4eb Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Fri, 4 Jul 2008 00:11:21 +0200 Subject: Catch non-existing dirs in (sh|run)-* commands Catch and report properly. --- src/nbblib/commands.py | 11 +++++++++-- src/nbblib/main.py | 4 ++++ 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() -- cgit