X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=scripts%2Fmup2ly.py;h=def68308d66679d84b4eb3c5af03e86d6d82d8fd;hb=4f0d84107a6a8b4215bb10c64aa3132f63bc01de;hp=da3a43be25ca717202027999b3ce649058871018;hpb=7e9683689ef1037bcb261d2804242aecaaf632a7;p=lilypond.git diff --git a/scripts/mup2ly.py b/scripts/mup2ly.py index da3a43be25..def68308d6 100644 --- a/scripts/mup2ly.py +++ b/scripts/mup2ly.py @@ -47,7 +47,7 @@ else: sys.path.append (os.path.join (datadir, 'python')) sys.path.append (os.path.join (datadir, 'python/out')) -program_name = 'mup2ly' +program_name = sys.argv[0] program_version = '@TOPLEVEL_VERSION@' original_dir = os.getcwd () temp_dir = os.path.join (original_dir, '%s.dir' % program_name) @@ -55,9 +55,10 @@ errorport = sys.stderr keep_temp_dir_p = 0 verbose_p = 0 +localedir = '@localedir@' try: import gettext - gettext.bindtextdomain ('lilypond', '@localedir@') + gettext.bindtextdomain ('lilypond', localedir) gettext.textdomain ('lilypond') _ = gettext.gettext except: @@ -66,15 +67,15 @@ except: program_name = 'mup2ly' -help_summary = _ ("Convert mup to LilyPond source") +help_summary = _ ("Convert mup to LilyPond source.") option_definitions = [ ('', 'd', 'debug', _ ("debug")), ('NAME[=EXP]', 'D', 'define', _ ("define macro NAME [optional expansion EXP]")), - ('', 'h', 'help', _ ("this help")), + ('', 'h', 'help', _ ("print this help")), ('FILE', 'o', 'output', _ ("write output to FILE")), ('', 'E', 'pre-process', _ ("only pre-process")), - ('', 'V', 'verbose', _ ("verbose")), + ('', 'V', 'verbose', _ ("be verbose")), ('', 'v', 'version', _ ("print version number")), ('', 'w', 'warranty', _ ("show warranty and copyright")), ] @@ -85,28 +86,6 @@ option_definitions = [ # # source file of the GNU LilyPond music typesetter -# Handle bug in Python 1.6-2.1 -# -# there are recursion limits for some patterns in Python 1.6 til 2.1. -# fix this by importing pre instead. Fix by Mats. - -# todo: should check Python version first. -try: - import pre - re = pre - del pre -except ImportError: - import re - -# Attempt to fix problems with limited stack size set by Python! -# Sets unlimited stack size. Note that the resource module only -# is available on UNIX. -try: - import resource - resource.setrlimit (resource.RLIMIT_STACK, (-1, -1)) -except: - pass - try: import gettext gettext.bindtextdomain ('lilypond', localedir) @@ -126,14 +105,13 @@ def identify (): def warranty (): identify () sys.stdout.write ('\n') - sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001--2002')) + sys.stdout.write (_ ('Copyright (c) %s by') % '2001--2006') sys.stdout.write ('\n') sys.stdout.write (' Han-Wen Nienhuys') sys.stdout.write (' Jan Nieuwenhuizen') - sys.stdout.write ('\n') - sys.stdout.write (_ (r''' -Distributed under terms of the GNU General Public License. It comes with -NO WARRANTY.''')) + sys.stdout.write ('\n\n') + sys.stdout.write (_ ("Distributed under terms of the GNU General Public License.")) + sys.stdout.write (_ ("It comes with NO WARRANTY.")) sys.stdout.write ('\n') def progress (s): @@ -182,9 +160,9 @@ def option_help_str (o): if o[1]: sh = '-%s' % o[1] - sep = ' ' + sep = ' ' if o[1] and o[2]: - sep = ',' + sep = ', ' long = '' if o[2]: @@ -216,22 +194,24 @@ def options_help_str (opts): return str def help (): - ls = [(_ ("Usage: %s [OPTION]... FILE") % program_name), - ('\n\n'), - (help_summary), - ('\n\n'), - (_ ("Options:")), - ('\n'), - (options_help_str (option_definitions)), - ('\n\n'), - (_ ("Report bugs to %s") % 'bug-lilypond@gnu.org'), - ('\n')] + ls = [(_ ("Usage: %s [OPTIONS]... FILE") % program_name), + ('\n\n'), + (help_summary), + ('\n\n'), + (_ ("Options:")), + ('\n'), + (options_help_str (option_definitions)), + ('\n\n'), + (_ ("Report bugs to %s.") % + "http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs"), + ('\n')] map (sys.stdout.write, ls) def setup_temp (): """ - Create a temporary directory, and return its name. + Create a temporary directory, and return its name. """ + global temp_dir if not keep_temp_dir_p: temp_dir = tempfile.mktemp (program_name) @@ -289,23 +269,6 @@ def cp_to_dir (pattern, dir): map (lambda x, d=dir: shutil.copy2 (x, os.path.join (d, x)), files) -# Python < 1.5.2 compatibility -# -# On most platforms, this is equivalent to -#`normpath(join(os.getcwd()), PATH)'. *Added in Python version 1.5.2* -if os.path.__dict__.has_key ('abspath'): - abspath = os.path.abspath -else: - def abspath (path): - return os.path.normpath (os.path.join (os.getcwd (), path)) - -if os.__dict__.has_key ('makedirs'): - makedirs = os.makedirs -else: - def makedirs (dir, mode=0777): - system ('mkdir -p %s' % dir) - - def mkdir_p (dir, mode=0777): if not os.path.isdir (dir): makedirs (dir, mode) @@ -454,8 +417,8 @@ class Slur: e= self.end_chord if e and s: - s.note_suffix = s.note_suffix + '(' - e.note_prefix = ')' + e.note_prefix + s.note_suffix = s.note_suffix + '-(' + e.note_prefix = e.note_suffix + "-)" else: sys.stderr.write ("\nOrphaned slur") @@ -524,7 +487,7 @@ class Voice: str = str + ln id = self.idstring () - str = '''%s = \\context Voice = %s \\notes { + str = '''%s = \\context Voice = %s { %s } @@ -566,9 +529,9 @@ class Key: if self.sharps and self.flats: k = '\\keysignature %s ' % 'TODO' elif self.sharps: - k = '\\notes\\key %s \major' % key_sharps[self.sharps] + k = '\\key %s \major' % key_sharps[self.sharps] elif self.flats: - k = '\\notes\\key %s \major' % key_flats[self.flats] + k = '\\key %s \major' % key_flats[self.flats] return k class Time: @@ -637,8 +600,8 @@ class Staff: str = str + v.dump() refs = refs + '\n \\' + v.idstring () str = str + ''' -%s = \context Staff = %s <%s -> +%s = \context Staff = %s <<%s +>> ''' % (self.idstring (), self.idstring (), refs) return str @@ -720,19 +683,21 @@ class Chord: for p in self.pitches: if str: str = str + ' ' - str = str + pitch_to_lily_string (p) + sd + str = str + pitch_to_lily_string (p) - for s in self.scripts: - str = str + '-' + s str = self.note_prefix +str + self.note_suffix if len (self.pitches) > 1: str = '<%s>' % str elif self.multimeasure: - str = 'R' + sd + str = 'R' elif len (self.pitches) == 0: - str = 'r' + sd + str = 'r' + + str = str + sd + for s in self.scripts: + str = str + '-' + s str = self.chord_prefix + str + self.chord_suffix @@ -1097,9 +1062,9 @@ class Parser: str = str + ''' \score { - <%s - > - \paper {} + <<%s + >> + \layout {} \midi {} } ''' % refs @@ -1288,12 +1253,13 @@ if not files: files = ['-'] for f in files: - + h = None if f == '-': h = sys.stdin elif f and not os.path.isfile (f): f = strip_extension (f, '.mup') + '.mup' - h = open (f) + + h = open (f) progress ( _("Processing `%s'..." % f)) raw_lines = h.readlines () p = Pre_processor (raw_lines)