diff options
| author | Mikhail Osipov <m.osipov@corp.mail.ru> | 2013-11-05 12:29:32 +0400 |
|---|---|---|
| committer | Mikhail Osipov <mike.osipov@gmail.com> | 2013-11-05 22:48:08 +0400 |
| commit | 2bb39647a32c51e981070e08c5d3c4a5c2e631e4 (patch) | |
| tree | 92446a3d7956c640eeadf7b754a9bc1b48c3abe9 /cutter/splitter.py | |
| parent | 6cb3a8a1828ef2b3c480b6e4988a2421ec47d0c6 (diff) | |
check exceptions for Popen, error handling improved
Diffstat (limited to 'cutter/splitter.py')
| -rw-r--r-- | cutter/splitter.py | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/cutter/splitter.py b/cutter/splitter.py index 3109c14..534815b 100644 --- a/cutter/splitter.py +++ b/cutter/splitter.py @@ -239,12 +239,11 @@ class Splitter: path = os.path.join(self.dest, trackname) printf("copy %s -> %s", quote(file.path), quote(path)) + printf("\n" if self.opt.dry_run else ": ") + if self.opt.dry_run: - printf("\n") return - printf(": ") - try: shutil.copyfile(file.path, path) except Exception as err: @@ -255,20 +254,40 @@ class Splitter: self.tag(track, path) + @staticmethod + def print_command_error(name, stream): + status, msg = stream.get_status() + + cmd = stream.get_command() + printerr("%s failed (%s), command: %s", name, status, cmd) + for line in msg.split("\n"): + if len(line): + printf("> %s\n", line) + def open_decode(self, path): stream = formats.decoder_open(path, self.opt) if stream is None: printerr("%s: unsupported type", quote(path)) elif not stream.ready(): - printerr("decode failed, command: %s", stream.get_command()) + self.print_command_error("decode", stream) + stream = None + else: + if self.opt.verbose and self.opt.dry_run: + self.print_decode_info(path, stream) - status, msg = stream.get_status() - if not len(msg): - printerr("exit code %d", status) - else: - printerr("exit code %d, stderr:\n%s", status, msg) + return stream + + def open_encode(self, reader, path): + stream = self.encoder.open(reader, path, self.opt) + if self.opt.dry_run: + if self.opt.verbose: + debug("encode: %s", stream.get_command()) + return stream + + if not stream.ready(): + self.print_command_error("encode", stream) stream = None return stream @@ -280,9 +299,6 @@ class Splitter: info.type, info.bits_per_sample, info.sample_rate, info.channels) - def print_encode_info(self, stream): - debug("encode: %s", stream.get_command()) - @staticmethod def track_timerange(track): ts = "%8s -" % msf(track.begin) @@ -302,10 +318,7 @@ class Splitter: def split_file(self, file): stream = self.open_decode(file.path) if not stream: - return - - if self.opt.verbose and self.opt.dry_run: - self.print_decode_info(file.path, stream) + sys.exit(1) if file.ntracks() == 1: if not self.is_need_convert(stream.info()): @@ -324,19 +337,21 @@ class Splitter: trackname = self.track_name(track) path = os.path.join(self.dest, trackname) - printf("split %s (%s) -> %s", quote(file.path), ts, quote(trackname)) - printf("\n" if self.opt.dry_run else ": ") - stream.seek(track.begin) reader = stream.get_reader(self.track_length(track)) - out = self.encoder.open(reader, path, self.opt) + out = self.open_encode(reader, path) + + printf("split %s (%s) -> %s", quote(file.path), ts, quote(trackname)) + printf("\n" if self.opt.dry_run else ": ") if self.opt.dry_run: - if self.opt.verbose: - self.print_encode_info(out) continue + if out is None: + printf("FAILED\n") + sys.exit(1) + out.process() out.close() |
