chiark / gitweb /
Discard exitcode of subprocess in a better way
authorKarl Hasselström <kha@treskal.com>
Sat, 8 Dec 2007 08:27:22 +0000 (09:27 +0100)
committerKarl Hasselström <kha@treskal.com>
Sat, 8 Dec 2007 09:34:24 +0000 (10:34 +0100)
Discard the exit code in a way that meshes better with the existing
handling of exit codes.

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/log.py
stgit/run.py

index 56f7e0abfa2700dd84d5441d0dab123666b4f781..c5f71a24509061cc81804145924a40b34416f2c6 100644 (file)
@@ -141,6 +141,6 @@ def func(parser, options, args):
         raise CmdException, 'No changelog for patch "%s"' % name
 
     if options.graphical:
-        Run('gitk', log).run(exitcode = False)
+        Run('gitk', log).discard_exitcode().run()
     else:
         show_log(log, options)
index be5ff0fc58964e4b824f4c8960d6651c56d8bd10..fa304d039159d95730d0e96e540736a5d69ad443 100644 (file)
@@ -58,6 +58,8 @@ class Run:
             duration = datetime.datetime.now() - self.__starttime
             out.done('%1.3f s' % (duration.microseconds/1e6 + duration.seconds))
     def __check_exitcode(self):
+        if self.__good_retvals == None:
+            return
         if self.exitcode not in self.__good_retvals:
             raise self.exc('%s failed with code %d'
                            % (self.__cmd[0], self.exitcode))
@@ -78,7 +80,7 @@ class Run:
         self.__log_end(self.exitcode)
         self.__check_exitcode()
         return outdata
-    def __run_noio(self, exitcode = True):
+    def __run_noio(self):
         """Run without captured IO."""
         assert self.__indata == None
         self.__log_start()
@@ -88,11 +90,13 @@ class Run:
         except OSError, e:
             raise self.exc('%s failed: %s' % (self.__cmd[0], e))
         self.__log_end(self.exitcode)
-        if exitcode:
-            self.__check_exitcode()
+        self.__check_exitcode()
     def returns(self, retvals):
         self.__good_retvals = retvals
         return self
+    def discard_exitcode(self):
+        self.__good_retvals = None
+        return self
     def discard_stderr(self, discard = True):
         self.__discard_stderr = discard
         return self
@@ -129,9 +133,9 @@ class Run:
         else:
             raise self.exc('%s produced %d lines, expected 1'
                            % (self.__cmd[0], len(outlines)))
-    def run(self, exitcode = True):
+    def run(self):
         """Just run, with no IO redirection."""
-        self.__run_noio(exitcode = exitcode)
+        self.__run_noio()
     def xargs(self, xargs):
         """Just run, with no IO redirection. The extra arguments are
         appended to the command line a few at a time; the command is