X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=python%2Fbook_snippets.py;h=4bc4252e79da3bad9cb15876eb2f4218a4f24d2f;hb=5d84bfad4626892bcffd05adcced53c8a2329047;hp=f3a11ccca94fa97d5967fb286de53290ab1e604f;hpb=38e1cad48d14f0b0f9286b4bb8891051a5f82d1e;p=lilypond.git diff --git a/python/book_snippets.py b/python/book_snippets.py index f3a11ccca9..4bc4252e79 100644 --- a/python/book_snippets.py +++ b/python/book_snippets.py @@ -7,11 +7,8 @@ import re import os import copy import shutil -# TODO: We are using os.popen3, which has been deprecated since python 2.6. The -# suggested replacement is the Popen function of the subprocess module. -# Unfortunately, on windows this needs the msvcrt module, which doesn't seem -# to be available in GUB?!?!?! -# from subprocess import Popen, PIPE +import subprocess +import sys progress = ly.progress warning = ly.warning @@ -647,10 +644,20 @@ printing diff against existing file." % filename) if not os.path.isdir (dst_path): os.makedirs (dst_path) try: - os.link (src, dst) - except AttributeError: - shutil.copyfile (src, dst) - except OSError: + if (self.global_options.use_source_file_names + and isinstance (self, LilypondFileSnippet)): + fout = open (dst, 'w') + fin = open (src, 'r') + for line in fin.readlines (): + fout.write (line.replace (self.basename (), self.final_basename ())) + fout.close () + fin.close () + else: + try: + os.link (src, dst) + except AttributeError: + shutil.copyfile (src, dst) + except (IOError, OSError): error (_ ('Could not overwrite file %s') % dst) raise CompileError(self.basename()) @@ -740,10 +747,11 @@ printing diff against existing file." % filename) debug (_ ("Running through filter `%s'") % cmd, True) - # TODO: Use Popen once we resolve the problem with msvcrt in Windows: - (stdin, stdout, stderr) = os.popen3 (cmd) - # p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) - # (stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr) + closefds = True + if (sys.platform == "mingw32"): + closefds = False + p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=closefds) + (stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr) stdin.write (input) status = stdin.close ()