]> diplodocus.org Git - flac-archive/blobdiff - rewrite-tags
Oops, really unify, and also fix SubprocessError to consume the stderr stream.
[flac-archive] / rewrite-tags
index c44a27b5a93f7e304ffc6894aa863cd0d2050f71..a3b5eb6af818210f405dc5cfba11bea44148cd48 100755 (executable)
@@ -4,7 +4,6 @@ import os, sys
 import subprocess
 import tempfile
 from errno import EEXIST
-from subprocess import Popen, PIPE
 
 from flac_archive.tags import Tags
 
@@ -21,18 +20,19 @@ class SubprocessError(Exception):
         Exception.__init__(self, msg % (abs(status), command_msg))
         self.status = status
         self.command = command
-        self.stderr = stderr
+        self.stderr = ''.join(stderr)
 
 def get_tags(fn):
     tags = Tags()
 
     command = ['metaflac', '--no-utf8-convert', '--export-tags-to=-', fn]
-    p = Popen(command, stdout=PIPE)
+    p = subprocess.Popen(command, stdout=subprocess.PIPE,
+                         stderr=subprocess.STDOUT)
     tags.load(p.stdout)
 
     status = p.wait()
     if status != 0:
-        raise SubprocessError(status, command=command, stderr=p.stderr)
+        raise SubprocessError(status, command=command, stderr=p.stdout)
 
     return tags
 
@@ -41,11 +41,11 @@ def rewrite_track_tags(track, tags, fn, tmp):
     tmp.close()
     command = ['metaflac', '--no-utf8-convert', '--dont-use-padding',
                '--remove-all-tags', '--import-tags-from', tmp.name, fn]
-    p = Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-    stdout, stderr = p.communicate()
+    p = subprocess.Popen(command, stdout=subprocess.PIPE,
+                         stderr=subprocess.STDOUT)
     status = p.wait()
     if status != 0:
-        raise SubprocessError(status, command=command, stderr=stdout)
+        raise SubprocessError(status, command=command, stderr=p.stdout)
 
 def do_read(filenames):
     # Use this mapping of tag names to sets of tag values to detect global tags.