]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/mup2ly.py
fixjes
[lilypond.git] / scripts / mup2ly.py
index 208aa76ae377a1cde35738547e81a28d1177660e..81279de3f8e694871949a55cf3f102913ae924f3 100644 (file)
@@ -34,194 +34,57 @@ import __main__
 import operator
 import tempfile
 
-# let's not yet clutter lily's po with this mup converter junk
-def _ (s):
-       return s
 
-#sys.path.append ('@datadir@/python')
-#import gettext
-#gettext.bindtextdomain ('lilypond', '@localedir@')
-#gettext.textdomain('lilypond')
-#_ = gettext.gettext
+# if set, LILYPONDPREFIX must take prevalence
+# if datadir is not set, we're doing a build and LILYPONDPREFIX 
+datadir = '@datadir@'
+if os.environ.has_key ('LILYPONDPREFIX') \
+   or '@datadir@' == '@' + 'datadir' + '@':
+       datadir = os.environ['LILYPONDPREFIX']
+else:
+       datadir = '@datadir@'
 
+sys.path.append (os.path.join (datadir, 'python'))
+sys.path.append (os.path.join (datadir, 'python/out'))
 
-
-
-program_name = 'mup2ly'
-help_summary = _("Convert mup to ly")
-output = 0
-
-# lily_py.py -- options and stuff
-# 
-# source file of the GNU LilyPond music typesetter
-
-# BEGIN Library for these?
-# cut-n-paste from ly2dvi
-
+program_name = 'ly2dvi'
 program_version = '@TOPLEVEL_VERSION@'
-if program_version == '@' + 'TOPLEVEL_VERSION' + '@':
-       program_version = '1.3.142'
-
-
 original_dir = os.getcwd ()
-temp_dir = '%s.dir' % program_name
+temp_dir = os.path.join (original_dir,  '%s.dir' % program_name)
+errorport = sys.stderr
 keep_temp_dir_p = 0
 verbose_p = 0
 
-def identify ():
-       sys.stdout.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version))
-
-def warranty ():
-       identify ()
-       sys.stdout.write ('\n')
-       sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001'))
-       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
-absolutely NO WARRANTY.'''))
-       sys.stdout.write ('\n')
-
-def progress (s):
-        if s[-1] != '\n':
-                s = s + '\n'
-       sys.stderr.write (s)
-
-def warning (s):
-       sys.stderr.write (_ ("warning: ") + s)
-       sys.stderr.write ('\n')
-       
-               
-def error (s):
-       sys.stderr.write (_ ("error: ") + s)
-       sys.stderr.write ('\n')
-       raise _ ("Exiting ... ")
-
-def getopt_args (opts):
-       '''Construct arguments (LONG, SHORT) for getopt from  list of options.'''
-       short = ''
-       long = []
-       for o in opts:
-               if o[1]:
-                       short = short + o[1]
-                       if o[0]:
-                               short = short + ':'
-               if o[2]:
-                       l = o[2]
-                       if o[0]:
-                               l = l + '='
-                       long.append (l)
-       return (short, long)
-
-def option_help_str (o):
-       '''Transform one option description (4-tuple ) into neatly formatted string'''
-       sh = '  '       
-       if o[1]:
-               sh = '-%s' % o[1]
-
-       sep = ' '
-       if o[1] and o[2]:
-               sep = ','
-               
-       long = ''
-       if o[2]:
-               long= '--%s' % o[2]
-
-       arg = ''
-       if o[0]:
-               if o[2]:
-                       arg = '='
-               arg = arg + o[0]
-       return '  ' + sh + sep + long + arg
-
-
-def options_help_str (opts):
-       '''Convert a list of options into a neatly formatted string'''
-       w = 0
-       strs =[]
-       helps = []
-
-       for o in opts:
-               s = option_help_str (o)
-               strs.append ((s, o[3]))
-               if len (s) > w:
-                       w = len (s)
-
-       str = ''
-       for s in strs:
-               str = str + '%s%s%s\n' % (s[0], ' ' * (w - len(s[0])  + 3), s[1])
-       return str
-
-def help ():
-       sys.stdout.write (_ ("Usage: %s [OPTION]... FILE") % program_name)
-       sys.stdout.write ('\n\n')
-       sys.stdout.write (help_summary)
-       sys.stdout.write ('\n\n')
-       sys.stdout.write (_ ("Options:"))
-       sys.stdout.write ('\n')
-       sys.stdout.write (options_help_str (option_definitions))
-       sys.stdout.write ('\n')
-       warning (_ ("%s is far from completed.  Not all constructs are recognised.") % program_name)
-       sys.stdout.write ('\n')
-       sys.stdout.write (_ ("Report bugs to %s") % 'bug-gnu-music@gnu.org')
-       sys.stdout.write ('\n')
-       sys.exit (0)
-
-
-def setup_temp ():
-       global temp_dir
-       if not keep_temp_dir_p:
-               temp_dir = tempfile.mktemp (program_name)
-       try:
-               os.mkdir (temp_dir, 0777)
-       except OSError:
-               pass
-               
-       
-def system (cmd, ignore_error = 0):
-       if verbose_p:
-               progress (_ ("Invoking `%s\'") % cmd)
-       st = os.system (cmd)
-       if st:
-               msg =  ( _ ("error: ") + _ ("command exited with value %d") % st)
-               if ignore_error:
-                       sys.stderr.write (msg + ' ' + _ ("(ignored)") + ' ')
-               else:
-                       error (msg)
-
-       return st
+try:
+       import gettext
+       gettext.bindtextdomain ('lilypond', '@localedir@')
+       gettext.textdomain ('lilypond')
+       _ = gettext.gettext
+except:
+       def _ (s):
+               return s
 
 
-def cleanup_temp ():
-       if not keep_temp_dir_p:
-               if verbose_p:
-                       progress (_ ('Cleaning up `%s\'') % temp_dir)
-               system ('rm -rf %s' % temp_dir)
+program_name = 'mup2ly'
+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")),
+       ('FILE', 'o', 'output', _ ("write output to FILE")),
+       ('', 'E', 'pre-process', _ ("only pre-process")),
+       ('', 'V', 'verbose', _ ("verbose")),
+       ('', 'v', 'version', _ ("print version number")),
+       ('', 'w', 'warranty', _ ("show warranty and copyright")),
+       ]
 
-def set_setting (dict, key, val):
-       try:
-               val = string.atof (val)
-       except ValueError:
-               #warning (_ ("invalid value: %s") % `val`)
-               pass
 
-       try:
-               dict[key].append (val)
-       except KeyError:
-               warning (_ ("no such setting: %s") % `key`)
-               dict[key] = [val]
+from lilylib import *
 
-def strip_extension (f, ext):
-       (p, e) = os.path.splitext (f)
-       if e == ext:
-               e = ''
-       return p + e
 
-# END Library
 
+output = 0
 
 #
 # PMX cut and paste
@@ -1110,18 +973,6 @@ class Pre_processor:
                                                s = ''
 
 
-               
-option_definitions = [
-       ('', 'd', 'debug', _ ("debug")),
-       ('NAME[=EXP]', 'D', 'define', _ ("define macro NAME [optional expansion EXP]")),
-       ('', 'h', 'help', _ ("this help")),
-       ('FILE', 'o', 'output', _ ("write output to FILE")),
-       ('', 'E', 'pre-process', _ ("only pre-process")),
-       ('', 'V', 'verbose', _ ("verbose")),
-       ('', 'v', 'version', _ ("print version number")),
-       ('', 'w', 'warranty', _ ("show warranty and copyright")),
-       ]
-
 debug_p = 0
 only_pre_process_p = 0
 def debug (s):