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
def link_all_output_files (self, output_dir, output_dir_files, destination):
existing, missing = self.all_output_files (output_dir, output_dir_files)
if missing:
- print '\nMissing', missing
+ error (_ ('Missing files: %s') % ', '.join (missing))
raise CompileError(self.basename())
for name in existing:
if (self.global_options.use_source_file_names
if not os.path.isdir (dst_path):
os.makedirs (dst_path)
try:
- os.link (src, dst)
- except AttributeError:
- shutil.copyfile (src, dst)
- except OSError:
- print '\nCould not overwrite file', dst
+ 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())
def additional_files_to_consider (self, base, full):
map (consider_file, [base + '.tex',
base + '.eps',
+ base + '.pdf',
base + '.texidoc',
base + '.doctitle',
base + '-systems.texi',
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 ()