From c0c01f79c63952206d962a14b78236e5e0ae9147 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 7 Oct 1995 20:48:17 +0000 Subject: more elegant way to treat exit status --- Demo/pdist/rcslib.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'Demo/pdist/rcslib.py') diff --git a/Demo/pdist/rcslib.py b/Demo/pdist/rcslib.py index 4b34fd76489..43dcf0a07ef 100755 --- a/Demo/pdist/rcslib.py +++ b/Demo/pdist/rcslib.py @@ -53,7 +53,11 @@ def log(self, name_rev, otherflags = ''): """ f = self._open(name_rev, 'rlog ' + otherflags) data = f.read() - self._closepipe(f) + status = self._closepipe(f) + if status: + data = data + "%s: %s" % status + elif data[-1] == '\n': + data = data[:-1] return data def head(self, name_rev): @@ -84,7 +88,9 @@ def info(self, name_rev): if i > 0: key, value = line[:i], string.strip(line[i+1:]) dict[key] = value - self._closepipe(f) + status = self._closepipe(f) + if status: + raise IOError, status return dict # --- Methods that change files --- @@ -215,7 +221,9 @@ def islocked(self, name_rev): """ f = self._open(name_rev, 'rlog -L -R') line = f.readline() - self._closepipe(f) + status = self._closepipe(f) + if status: + raise IOError, status if not line: return None return self.realname(name_rev) == self.realname(line) @@ -247,7 +255,7 @@ def _open(self, name_rev, cmd = 'co -p', rflag = '-r'): namev = self.rcsname(name) if rev: cmd = cmd + ' ' + rflag + rev - return os.popen('%s %s' % (cmd, `namev`)) + return os.popen("%s %s" % (cmd, `namev`)) def _unmangle(self, name_rev): """INTERNAL: Normalize NAME_REV argument to (NAME, REV) tuple. @@ -270,8 +278,18 @@ def _unmangle(self, name_rev): def _closepipe(self, f): """INTERNAL: Close PIPE and print its exit status if nonzero.""" sts = f.close() - if sts: - raise IOError, "Exit status %d" % sts + if not sts: return None + detail, reason = divmod(sts, 256) + if reason == 0: return 'exit', detail # Exit status + signal = reason&0x7F + if signal == 0x7F: + code = 'stopped' + signal = detail + else: + code = 'killed' + if reason&0x80: + code = code + '(coredump)' + return code, signal def _system(self, cmd): """INTERNAL: run COMMAND in a subshell. -- cgit v1.2.3-65-gdbad