LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 | 2 |
3 import book_base as BookBase | 3 import book_base as BookBase |
4 import lilylib as ly | 4 import lilylib as ly |
5 global _;_=ly._ | 5 global _;_=ly._ |
| 6 import codecs |
6 import re | 7 import re |
7 import os | 8 import os |
8 import copy | 9 import copy |
9 import shutil | 10 import shutil |
10 import subprocess | 11 import subprocess |
11 import sys | 12 import sys |
12 | 13 |
13 progress = ly.progress | 14 progress = ly.progress |
14 warning = ly.warning | 15 warning = ly.warning |
15 error = ly.error | 16 error = ly.error |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 if os.path.exists (filename): | 603 if os.path.exists (filename): |
603 existing = open (filename, 'r').read () | 604 existing = open (filename, 'r').read () |
604 | 605 |
605 if self.relevant_contents (existing) != self.relevant_contents (self
.full_ly ()): | 606 if self.relevant_contents (existing) != self.relevant_contents (self
.full_ly ()): |
606 warning ("%s: duplicate filename but different contents of origi
nal file,\n\ | 607 warning ("%s: duplicate filename but different contents of origi
nal file,\n\ |
607 printing diff against existing file." % filename) | 608 printing diff against existing file." % filename) |
608 encoded = self.full_ly ().encode ('utf-8') | 609 encoded = self.full_ly ().encode ('utf-8') |
609 cmd = 'diff -u %s -' % filename | 610 cmd = 'diff -u %s -' % filename |
610 ly.stderr_write (self.filter_pipe (encoded, cmd).decode ('utf-8'
)) | 611 ly.stderr_write (self.filter_pipe (encoded, cmd).decode ('utf-8'
)) |
611 else: | 612 else: |
612 out = open (filename, 'w') | 613 out = codecs.open (filename, 'w', 'utf-8') |
613 out.write (self.full_ly ()) | 614 out.write (self.full_ly ()) |
614 open (path + '.txt', 'w').write ('image of music') | 615 open (path + '.txt', 'w').write ('image of music') |
615 | 616 |
616 def relevant_contents (self, ly): | 617 def relevant_contents (self, ly): |
617 return re.sub (r'\\(version|sourcefileline|sourcefilename)[^\n]*\n', '',
ly) | 618 return re.sub (r'\\(version|sourcefileline|sourcefilename)[^\n]*\n', '',
ly) |
618 | 619 |
619 def link_all_output_files (self, output_dir, output_dir_files, destination): | 620 def link_all_output_files (self, output_dir, output_dir_files, destination): |
620 existing, missing = self.all_output_files (output_dir, output_dir_files) | 621 existing, missing = self.all_output_files (output_dir, output_dir_files) |
621 if missing: | 622 if missing: |
622 error (_ ('Missing files: %s') % ', '.join (missing)) | 623 error (_ ('Missing files: %s') % ', '.join (missing)) |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 filename = path + '.ly' | 928 filename = path + '.ly' |
928 if os.path.exists (filename): | 929 if os.path.exists (filename): |
929 encoded = self.full_ly ().encode ('utf-8') | 930 encoded = self.full_ly ().encode ('utf-8') |
930 cmd = 'diff -u %s -' % filename | 931 cmd = 'diff -u %s -' % filename |
931 diff_against_existing = self.filter_pipe (encoded, cmd).decode ('utf
-8') | 932 diff_against_existing = self.filter_pipe (encoded, cmd).decode ('utf
-8') |
932 if diff_against_existing: | 933 if diff_against_existing: |
933 warning (_ ("%s: duplicate filename but different contents of co
nverted lilypond file,\n\ | 934 warning (_ ("%s: duplicate filename but different contents of co
nverted lilypond file,\n\ |
934 printing diff against existing file.") % filename) | 935 printing diff against existing file.") % filename) |
935 ly.stderr_write (diff_against_existing.decode ('utf-8')) | 936 ly.stderr_write (diff_against_existing.decode ('utf-8')) |
936 else: | 937 else: |
937 out = open (filename, 'w') | 938 out = codecs.open (filename, 'w', 'utf-8') |
938 out.write (self.full_ly ()) | 939 out.write (self.full_ly ()) |
939 out.close () | 940 out.close () |
940 open (path + '.txt', 'w').write ('image of music') | 941 open (path + '.txt', 'w').write ('image of music') |
941 | 942 |
942 | 943 |
943 | 944 |
944 class LilyPondVersionString (Snippet): | 945 class LilyPondVersionString (Snippet): |
945 """A string that does not require extra memory.""" | 946 """A string that does not require extra memory.""" |
946 def __init__ (self, type, match, formatter, line_number, global_options): | 947 def __init__ (self, type, match, formatter, line_number, global_options): |
947 Snippet.__init__ (self, type, match, formatter, line_number, global_opti
ons) | 948 Snippet.__init__ (self, type, match, formatter, line_number, global_opti
ons) |
948 | 949 |
949 def replacement_text (self): | 950 def replacement_text (self): |
950 return self.formatter.output_simple (self.type, self) | 951 return self.formatter.output_simple (self.type, self) |
951 | 952 |
952 | 953 |
953 snippet_type_to_class = { | 954 snippet_type_to_class = { |
954 'lilypond_file': LilypondFileSnippet, | 955 'lilypond_file': LilypondFileSnippet, |
955 'lilypond_block': LilypondSnippet, | 956 'lilypond_block': LilypondSnippet, |
956 'lilypond': LilypondSnippet, | 957 'lilypond': LilypondSnippet, |
957 'include': IncludeSnippet, | 958 'include': IncludeSnippet, |
958 'lilypondversion': LilyPondVersionString, | 959 'lilypondversion': LilyPondVersionString, |
959 'musicxml_file': MusicXMLFileSnippet, | 960 'musicxml_file': MusicXMLFileSnippet, |
960 } | 961 } |
LEFT | RIGHT |