]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/etf2ly.py
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scripts / etf2ly.py
index 126288f6766723928689a2bd15b14dca78ca467f..24dc562871abdb74590cde5cb8cd8063969fcde0 100644 (file)
@@ -1,5 +1,20 @@
 #!@TARGET_PYTHON@
 
+# This file is part of LilyPond, the GNU music typesetter.
+#
+# LilyPond is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# LilyPond is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+
 # info mostly taken from looking at files. See also
 # http://lilypond.org/wiki/?EnigmaTransportFormat
 
@@ -30,34 +45,20 @@ import __main__
 import getopt
 import sys
 import re
-import string
 import os
 
 program_name = sys.argv[0]
 
+authors = ('Jan Nieuwenhuizen <janneke@gnu.org>',
+           'Han-Wen Nienhuys <hanwen@xs4all.nl>')
+
 version = '@TOPLEVEL_VERSION@'
 if version == '@' + 'TOPLEVEL_VERSION' + '@':
     version = '(unknown version)'           # uGUHGUHGHGUGH
 
-
-################################################################
-# Users of python modules should include this snippet.
-#
-
-
-
-
-for d in ['@lilypond_datadir@',
-          '@lilypond_libdir@']:
-    sys.path.insert (0, os.path.join (d, 'python'))
-
-
-# dynamic relocation, for GUB binaries.
-bindir = os.path.abspath (os.path.split (sys.argv[0])[0])
-for p in ['share', 'lib']:
-    datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
-    sys.path.insert (0, datadir)
-
+"""
+@relocate-preamble@
+"""
 
 ################################################################
 
@@ -284,7 +285,7 @@ class Slur:
             if not cs or not ce:
                 raise IndexError
             
-            cs.note_suffix = '-(' + cs.note_suffix 
+            cs.note_suffix = '-(' + cs.note_suffix
             ce.note_suffix = ce.note_suffix + '-)'
             
         except IndexError:
@@ -525,7 +526,7 @@ class Frame:
         if left[0]:
             str = str + rational_to_lily_skip (left)
 
-        str = str + '  | \n'
+        str = str + '  |\n'
         return str
         
 def encodeint (i):
@@ -575,7 +576,7 @@ class Staff:
                     last_time = g.timesig
 
                 if 'start' in g.repeats:
-                    e = e + ' \\bar "|:" ' 
+                    e = e + ' \\bar ".|:" '
 
 
                 # we don't attempt voltas since they fail easily.
@@ -588,7 +589,7 @@ class Staff:
                     if g.bracket == 'start':
                         strs.append ('"0."')
 
-                    str = string.join (map (lambda x: '(volta %s)' % x, strs))
+                    str = ' '.join (['(volta %s)' % x for x in strs])
                     
                     e = e + ' \\set Score.repeatCommands =  #\'(%s) ' % str
 
@@ -607,7 +608,7 @@ class Staff:
             if g:
                 gap = rat_add (gap, g.length ())
                 if 'stop' in g.repeats:
-                    k = k + ' \\bar ":|" '
+                    k = k + ' \\bar ":|." '
                 
         k = '%sglobal = { %s }\n\n ' % (self.staffid (), k)
         return k
@@ -632,7 +633,7 @@ class Staff:
                     fr = m.frames[x]
                 except IndexError:
                     sys.stderr.write ("Skipping nonexistent frame %d\n" % x)
-                    laystr = laystr + "%% non existent frame %d (skipped) \n" % x
+                    laystr = laystr + "%% non existent frame %d (skipped)\n" % x
                 if fr:
                     first_frame = fr
                     if gap <> (0,1):
@@ -827,7 +828,7 @@ Return: (value, rest-of-STR)
             str = str[1:]
 
         
-        return (string.atol (hex, 16), str)
+        return (long (hex, 16), str)
     elif str[0] == '"':
         str = str[1:]
         s = ''
@@ -842,7 +843,7 @@ Return: (value, rest-of-STR)
             dec = dec  + str[0]
             str = str[1:]
             
-        return (string.atoi (dec), str)
+        return (int (dec), str)
     else:
         sys.stderr.write ("cannot convert `%s'\n" % str)
         return (None, str)
@@ -861,10 +862,10 @@ def parse_etf_file (fn, tag_dict):
     f = open (fn)
     
     gulp = re.sub ('[\n\r]+', '\n',  f.read ())
-    ls = string.split (gulp, '\n^')
+    ls = gulp.split ('\n^')
 
     etf_file_dict = {}
-    for k in tag_dict.keys (): 
+    for k in tag_dict:
         etf_file_dict[k] = {}
 
     last_tag = None
@@ -876,7 +877,7 @@ def parse_etf_file (fn, tag_dict):
         if m and tag_dict.has_key (m.group (1)):
             tag = m.group (1)
 
-            indices = tuple (map (string.atoi, string.split (m.group (2), ',')))
+            indices = tuple ([int (s) for s in m.group (2).split (',')])
             content = l[m.end (2)+1:]
 
 
@@ -1130,11 +1131,13 @@ class Etf_file:
 
         
         while c and c.number <> endno:
-            thread.append (c)
+            d = c # hack to avoid problem with scripts/build/grand-replace.py
+            thread.append (d)
             c = c.next
 
         if c: 
-            thread.append (c)
+            d = c # hack to avoid problem with scripts/build/grand-replace.py
+            thread.append (d)
         
         return thread
 
@@ -1157,7 +1160,7 @@ class Etf_file:
             
         if staffs:
             str += '\\version "2.3.25"\n'
-            str = str + '<<\n  %s\n>> } ' % string.join (staffs)
+            str = str + '<<\n  %s\n>> } ' % ' '.join (staffs)
             
         return str
 
@@ -1179,24 +1182,30 @@ def identify():
 def warranty ():
     identify ()
     sys.stdout.write ('''
-Copyright (c) %s by
+%s
 
- Han-Wen Nienhuys
- Jan Nieuwenhuizen
+  %s
 
 %s
 %s
-''' % ( '2001--2006',
-   _('Distributed under terms of the GNU General Public License.'),
-   _('It comes with NO WARRANTY.')))
-
-
+''' % ( _ ('Copyright (c) %s by') % '2001--2015',
+        '\n  '.join (authors),
+        _ ('Distributed under terms of the GNU General Public License.'),
+        _ ('It comes with NO WARRANTY.')))
 
 def get_option_parser ():
     p = ly.get_option_parser (usage=_ ("%s [OPTION]... ETF-FILE") % 'etf2ly',
-                 version="etf2ly (LilyPond) @TOPLEVEL_VERSION@",
                  description=_ ("""Enigma Transport Format is a format used by Coda Music Technology's
-Finale product.  etf2ly converts a subset of ETF to a ready-to-use LilyPond file."""))
+Finale product.  etf2ly converts a subset of ETF to a ready-to-use LilyPond file.
+"""),
+                 add_help_option=False)
+    p.add_option("-h", "--help",
+                 action="help",
+                 help=_ ("show this help and exit"))
+    p.version = "etf2ly (LilyPond) @TOPLEVEL_VERSION@"
+    p.add_option("--version",
+                 action="version",
+                 help=_ ("show version number and exit"))
     p.add_option ('-o', '--output', help=_ ("write output to FILE"),
            metavar=_("FILE"),
            action='store')
@@ -1204,10 +1213,11 @@ Finale product.  etf2ly converts a subset of ETF to a ready-to-use LilyPond file
            action='store_true',
            ),
 
-    p.add_option_group ('bugs',
-                        description=(_ ('Report bugs via')
-                                     + ''' http://post.gmane.org/post.php'''
-                                     '''?group=gmane.comp.gnu.lilypond.bugs\n'''))
+    p.add_option_group ('',
+                        description=(
+            _ ('Report bugs via %s')
+            % 'http://post.gmane.org/post.php'
+            '?group=gmane.comp.gnu.lilypond.bugs') + '\n')
     return p
 
 def do_options ():
@@ -1242,8 +1252,6 @@ for f in files:
     sys.stderr.write ('Writing `%s\'' % out_filename)
     ly = e.dump()
 
-    
-    
     fo = open (out_filename, 'w')
     fo.write ('%% lily was here -- automatically converted by etf2ly from %s\n' % f)
     fo.write(ly)