X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=scripts%2Fetf2ly.py;h=54daa94decea6db273a297308eaa815797fb1321;hb=8cab78caa0db1ba14f2e52e4c1ddbb541ea0e5cb;hp=a5291e92ad94eac4be03ade05c1ee09da3983822;hpb=cc24fb904390aaf7d011791e42eb7da020bb2b58;p=lilypond.git diff --git a/scripts/etf2ly.py b/scripts/etf2ly.py index a5291e92ad..54daa94dec 100644 --- a/scripts/etf2ly.py +++ b/scripts/etf2ly.py @@ -30,44 +30,20 @@ import __main__ import getopt import sys import re -import string import os program_name = sys.argv[0] +authors = ('Jan Nieuwenhuizen ', + 'Han-Wen Nienhuys ') + version = '@TOPLEVEL_VERSION@' if version == '@' + 'TOPLEVEL_VERSION' + '@': version = '(unknown version)' # uGUHGUHGHGUGH - -################################################################ -# Users of python modules should include this snippet. -# -libdir = '@local_lilypond_libdir@' -if not os.path.isdir (libdir): - libdir = '@lilypond_libdir@' - -# ugh -datadir = '@local_lilypond_datadir@' -if os.environ.has_key ('LILYPONDPREFIX'): - datadir = os.environ['LILYPONDPREFIX'] - while datadir[-1] == os.sep: - datadir= datadir[:-1] - libdir = datadir.replace ('/share/', '/lib/') - -if os.path.exists (os.path.join (datadir, 'lib/lilypond/@TOPLEVEL_VERSION@/')): - libdir = os.path.join (libdir, 'lib/lilypond/@TOPLEVEL_VERSION@/') - -if os.path.exists (os.path.join (datadir, 'lib/lilypond/current/')): - libdir = os.path.join (libdir, 'lib/lilypond/current/') - -sys.path.insert (0, os.path.join (libdir, 'python')) - -# dynamic relocation, for GUB binaries. -bindir = 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@ +""" ################################################################ @@ -294,7 +270,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: @@ -535,7 +511,7 @@ class Frame: if left[0]: str = str + rational_to_lily_skip (left) - str = str + ' | \n' + str = str + ' |\n' return str def encodeint (i): @@ -598,7 +574,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 @@ -642,7 +618,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): @@ -837,7 +813,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 = '' @@ -852,9 +828,9 @@ 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 ("can't convert `%s'\n" % str) + sys.stderr.write ("cannot convert `%s'\n" % str) return (None, str) @@ -871,10 +847,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 @@ -886,7 +862,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:] @@ -1167,7 +1143,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 @@ -1189,35 +1165,42 @@ 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--2009', + '\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='etf2ly [OPTIONS]... ETF-FILE', - version="etf2ly (LilyPond) @TOPLEVEL_VERSION@", - description=_("""Enigma Transport Format is a format used by Coda Music Technology's -Finale product. This program will convert a subset of ETF to a -ready-to-use lilypond file.""")) - p.add_option ('-o', '--output', help=_("write output to FILE"), + p = ly.get_option_parser (usage=_ ("%s [OPTION]... ETF-FILE") % 'etf2ly', + 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. +"""), + 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') - p.add_option ('-w', '--warranty', help=_ ("show warranty"), + p.add_option ('-w', '--warranty', help=_ ("show warranty and copyright"), 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 (): @@ -1252,8 +1235,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)