]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix references when using --use-source-file-names (issue 4046)
authorJulien Rioux <julien.rioux@gmail.com>
Thu, 7 Aug 2014 18:25:03 +0000 (20:25 +0200)
committerJulien Rioux <julien.rioux@gmail.com>
Thu, 21 Aug 2014 19:02:44 +0000 (21:02 +0200)
python/book_snippets.py

index 69fdc4fa6867401cdcd40fecbf16b4e6324ed4b7..4bc4252e79da3bad9cb15876eb2f4218a4f24d2f 100644 (file)
@@ -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())