]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/book_snippets.py
Merge branch 'master' into lilypond/translation
[lilypond.git] / python / book_snippets.py
index a65fe4d0b775a5e1c7f5619afaa0b9dbce07f1da..47b683471657e39c1fcf3ef764bf2e8bbaf22075 100644 (file)
@@ -38,14 +38,12 @@ EXAMPLEINDENT = 'exampleindent'
 FILENAME = 'filename'
 FILTER = 'filter'
 FRAGMENT = 'fragment'
-LANG = 'lang'    ## TODO: This is handled nowhere!
 LAYOUT = 'layout'
 LILYQUOTE = 'lilyquote'
 LINE_WIDTH = 'line-width'
 NOFRAGMENT = 'nofragment'
 NOGETTEXT = 'nogettext'
 NOINDENT = 'noindent'
-NOQUOTE = 'noquote'
 INDENT = 'indent'
 NORAGGED_RIGHT = 'noragged-right'
 NOTES = 'body'
@@ -68,7 +66,6 @@ VERSION = 'lilypondversion'
 
 # NOTIME and NOGETTEXT have no opposite so they aren't part of this
 # dictionary.
-# NOQUOTE is used internally only.
 no_options = {
     NOFRAGMENT: FRAGMENT,
     NOINDENT: INDENT,
@@ -92,7 +89,6 @@ simple_options = [
     PRINTFILENAME,
     DOCTITLE,
     TEXIDOC,
-    LANG,
     VERBATIM,
     FILENAME,
     ALT,
@@ -145,23 +141,6 @@ snippet_options = {
 
 
 
-FRAGMENT_LY = r'''
-%(notes_string)s
-{
-
-
-%% ****************************************************************
-%% ly snippet contents follows:
-%% ****************************************************************
-%(code)s
-
-
-%% ****************************************************************
-%% end ly snippet
-%% ****************************************************************
-}
-'''
-
 def classic_lilypond_book_compatibility (key, value):
     if key == 'singleline' and value == None:
         return (RAGGED_RIGHT, None)
@@ -196,7 +175,6 @@ PREAMBLE_LY = '''%%%% Generated by %(program_name)s
 
 \paper {
   %(paper_string)s
-  force-assignment = #""
   line-width = #(- line-width (* mm  %(padding_mm)f))
 }
 
@@ -222,10 +200,23 @@ FULL_LY = '''
 %% ****************************************************************
 '''
 
+FRAGMENT_LY = r'''
+%(notes_string)s
+{
 
 
+%% ****************************************************************
+%% ly snippet contents follows:
+%% ****************************************************************
+%(code)s
 
 
+%% ****************************************************************
+%% end ly snippet
+%% ****************************************************************
+}
+'''
+
 
 
 
@@ -460,10 +451,6 @@ left-margin-default right-margin-default)"
         return self.option_list
 
     def compose_ly (self, code):
-        if FRAGMENT in self.option_dict:
-            body = FRAGMENT_LY
-        else:
-            body = FULL_LY
 
         # Defaults.
         relative = 1
@@ -574,6 +561,10 @@ left-margin-default right-margin-default)"
         d = globals().copy()
         d.update (locals())
         d.update (self.global_options.information)
+        if FRAGMENT in self.option_dict:
+            body = FRAGMENT_LY
+        else:
+            body = FULL_LY
         return (PREAMBLE_LY + body) % d
 
     def get_checksum (self):
@@ -686,7 +677,8 @@ printing diff against existing file." % filename)
 
         # UGH - junk self.global_options
         skip_lily = self.global_options.skip_lilypond_run
-        for required in [base + '.ly']:
+        for required in [base + '.ly',
+                         base + '.txt']:
             require_file (required)
         if not skip_lily:
             require_file (base + '-systems.count')
@@ -867,19 +859,19 @@ class MusicXMLFileSnippet (LilypondFileSnippet):
 
     def convert_from_musicxml (self):
         name = self.filename
-        option_list = []
+        xml2ly_option_list = []
         for (key, value) in self.option_dict.items ():
             cmd_key = self.musicxml_options_dict.get (key, None)
             if cmd_key == None:
                 continue
             if value == None:
-                option_list.append (cmd_key)
+                xml2ly_option_list.append (cmd_key)
             else:
-                option_list.append (cmd_key + '=' + value)
-        if ('.mxl' in name) and ('--compressed' not in option_list):
-            option_list.append ('--compressed')
+                xml2ly_option_list.append (cmd_key + '=' + value)
+        if ('.mxl' in name) and ('--compressed' not in xml2ly_option_list):
+            xml2ly_option_list.append ('--compressed')
             self.compressed = True
-        opts = " ".join (option_list)
+        opts = " ".join (xml2ly_option_list)
         progress (_ ("Converting MusicXML file `%s'...\n") % self.filename)
 
         ly_code = self.filter_pipe (self.contents, 'musicxml2ly %s --out=- - ' % opts)
@@ -915,8 +907,8 @@ class MusicXMLFileSnippet (LilypondFileSnippet):
         if os.path.exists (xmlfilename):
             diff_against_existing = self.filter_pipe (self.contents, 'diff -u %s - ' % xmlfilename)
             if diff_against_existing:
-                warning ("%s: duplicate filename but different contents of orginal file,\n\
-printing diff against existing file." % xmlfilename)
+                warning (_ ("%s: duplicate filename but different contents of orginal file,\n\
+printing diff against existing file.") % xmlfilename)
                 ly.stderr_write (diff_against_existing)
         else:
             out = file (xmlfilename, 'w')
@@ -928,13 +920,15 @@ printing diff against existing file." % xmlfilename)
         if os.path.exists (filename):
             diff_against_existing = self.filter_pipe (self.full_ly (), 'diff -u %s -' % filename)
             if diff_against_existing:
-                warning ("%s: duplicate filename but different contents of converted lilypond file,\n\
-printing diff against existing file." % filename)
+                warning (_ ("%s: duplicate filename but different contents of converted lilypond file,\n\
+printing diff against existing file.") % filename)
                 ly.stderr_write (diff_against_existing)
         else:
             out = file (filename, 'w')
             out.write (self.full_ly ())
             out.close ()
+            file (path + '.txt', 'w').write ('image of music')
+
 
 
 class LilyPondVersionString (Snippet):