From: Date: Wed, 26 Dec 2012 18:09:35 +0000 (-0800) Subject: Expand SubprocessError to report the failing command, and test it. X-Git-Url: https://diplodocus.org/git/flac-archive/commitdiff_plain/abec15c04fc2dac73b42c638aae54d308856c7a9?hp=103ef1e59f02e8154e96d7e944fb0319dda09c31 Expand SubprocessError to report the failing command, and test it. --- diff --git a/rewrite-tags b/rewrite-tags index 84eb1f8..105b570 100755 --- a/rewrite-tags +++ b/rewrite-tags @@ -8,24 +8,30 @@ from org.diplodocus.util import run_or_die from flac_archive.tags import Tags class SubprocessError(Exception): - def __init__(self, status, stderr=None): + def __init__(self, status, command=None, stderr=None): + if command is None: + command_msg = None + else: + command_msg = ': ' + ' '.join(command) if status < 0: - msg = 'exited due to signal %d' + msg = 'exited due to signal %d%s' else: - msg = 'exit status %d' - Exception.__init__(self, msg % (abs(status),)) + msg = 'exit status %d%s' + Exception.__init__(self, msg % (abs(status), command_msg)) self.status = status + self.command = command self.stderr = stderr def get_tags(fn): tags = Tags() - p = Popen(['metaflac', '--no-utf8-convert', '--export-tags-to=-', fn], - stdout=PIPE) + + command = ['metaflac', '--no-utf8-convert', '--export-tags-to=-', fn] + p = Popen(command, stdout=PIPE) tags.load(p.stdout) status = p.wait() if status != 0: - raise SubprocessError(status, p.stderr) + raise SubprocessError(status, command=command, stderr=p.stderr) return tags @@ -57,6 +63,7 @@ def do_read(filenames): for track, tags in coll_tags._tracks.iteritems(): del tags[tag] print '\n'.join(coll_tags.all()) + return 0 def main(args): if len(args) < 3: