]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Fix reading compressed files from stdin
authorReinhold Kainhofer <reinhold@kainhofer.com>
Sat, 23 Jul 2011 17:30:05 +0000 (19:30 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Mon, 25 Jul 2011 12:30:46 +0000 (14:30 +0200)
scripts/musicxml2ly.py

index c98da61e9f0be38c69683c16db647e895c8f39a8..defc576b1f6748971657f83f0f2e189847579b04 100644 (file)
@@ -7,6 +7,7 @@ import os
 import string
 import codecs
 import zipfile
+import tempfile
 import StringIO
 
 """
@@ -2788,7 +2789,17 @@ def read_musicxml (filename, compressed, use_lxml):
     if compressed:
         if filename == "-":
              progress (_ ("Input is compressed, extracting raw MusicXML data from stdin") )
-             z = zipfile.ZipFile (sys.stdin)
+             # unfortunately, zipfile.ZipFile can't read directly from
+             # stdin, so copy everything from stdin to a temp file and read
+             # that. TemporaryFile() will remove the file when it is closed.
+             tmp = tempfile.TemporaryFile()
+             sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0) # Make sys.stdin binary
+             bytes_read = sys.stdin.read (8192)
+             while bytes_read:
+                 for b in bytes_read:
+                     tmp.write(b)
+                 bytes_read = sys.stdin.read (8192)
+             z = zipfile.ZipFile (tmp, "r")
         else:
             progress (_ ("Input file %s is compressed, extracting raw MusicXML data") % filename)
             z = zipfile.ZipFile (filename, "r")