Return diff command error code.

This commit is contained in:
Bastian Kleineidam 2010-03-11 17:54:09 +01:00
parent 9d859bc21c
commit 282701e675
2 changed files with 9 additions and 5 deletions

View File

@ -342,7 +342,7 @@ def run_archive_cmdlist (archive_cmdlist):
cmdlist, runkwargs = archive_cmdlist cmdlist, runkwargs = archive_cmdlist
else: else:
cmdlist, runkwargs = archive_cmdlist, {} cmdlist, runkwargs = archive_cmdlist, {}
util.run(cmdlist, **runkwargs) util.run_checked(cmdlist, **runkwargs)
def make_file_readable (filename): def make_file_readable (filename):
@ -440,10 +440,10 @@ def handle_archive (archive, command, *args, **kwargs):
"""Handle archive file command; with nice error reporting.""" """Handle archive file command; with nice error reporting."""
try: try:
if command == "diff": if command == "diff":
_diff_archives(archive, args[0]) res = _diff_archives(archive, args[0])
else: else:
_handle_archive(archive, command, *args, **kwargs) _handle_archive(archive, command, *args, **kwargs)
res = 0 res = 0
except KeyboardInterrupt, msg: except KeyboardInterrupt, msg:
util.log_info("aborted") util.log_info("aborted")
res = 1 res = 1
@ -465,7 +465,7 @@ def _diff_archives (archive1, archive2):
try: try:
dir1 = _handle_archive(archive1, 'extract', outdir=tmpdir1) dir1 = _handle_archive(archive1, 'extract', outdir=tmpdir1)
dir2 = _handle_archive(archive2, 'extract', outdir=tmpdir2) dir2 = _handle_archive(archive2, 'extract', outdir=tmpdir2)
util.run([diff, "-BurN", dir1, dir2]) return util.run([diff, "-BurN", dir1, dir2])
finally: finally:
shutil.rmtree(tmpdir1, onerror=util.log_error) shutil.rmtree(tmpdir1, onerror=util.log_error)
shutil.rmtree(tmpdir2, onerror=util.log_error) shutil.rmtree(tmpdir2, onerror=util.log_error)

View File

@ -85,6 +85,11 @@ def backtick (cmd):
def run (cmd, **kwargs): def run (cmd, **kwargs):
"""Run command and raise PatoolError on error."""
return subprocess.call(cmd, **kwargs)
def run_checked (cmd, **kwargs):
"""Run command and raise PatoolError on error.""" """Run command and raise PatoolError on error."""
retcode = subprocess.call(cmd, **kwargs) retcode = subprocess.call(cmd, **kwargs)
if retcode: if retcode:
@ -92,7 +97,6 @@ def run (cmd, **kwargs):
raise PatoolError(msg) raise PatoolError(msg)
return retcode return retcode
@memoized @memoized
def guess_mime (filename): def guess_mime (filename):
"""Guess the MIME type of given filename using file(1) and if that """Guess the MIME type of given filename using file(1) and if that