From 512b082a1c470d0315ae8c5f48da3b374a2de716 Mon Sep 17 00:00:00 2001 From: Julien Rioux Date: Thu, 7 Aug 2014 20:25:03 +0200 Subject: [PATCH] Fix references when using --use-source-file-names (issue 4046) --- python/book_snippets.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/python/book_snippets.py b/python/book_snippets.py index 69fdc4fa68..4bc4252e79 100644 --- a/python/book_snippets.py +++ b/python/book_snippets.py @@ -644,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()) -- 2.39.5