From: Han-Wen Nienhuys Date: Wed, 1 Mar 2006 17:59:04 +0000 (+0000) Subject: * scripts/etf2ly.py (do_options): use optparse X-Git-Tag: release/2.7.37~20 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=dc4891890731eb60289e338449e63aa9072bcf65;p=lilypond.git * scripts/etf2ly.py (do_options): use optparse * scripts/midi2ly.py: optparse, strip lilylib copy. --- diff --git a/ChangeLog b/ChangeLog index 6a402d0dbe..2ac51f467a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2006-03-01 Han-Wen Nienhuys + * scripts/etf2ly.py (do_options): use optparse + * scripts/midi2ly.py: optparse, strip lilylib copy. * scripts/abc2ly.py (voices): use optparse. diff --git a/scripts/etf2ly.py b/scripts/etf2ly.py index 225d23397b..18a33a4324 100644 --- a/scripts/etf2ly.py +++ b/scripts/etf2ly.py @@ -38,6 +38,41 @@ program_name = sys.argv[0] 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) + +################################################################ + +import lilylib as ly +_ = ly._ finale_clefs= ['treble', 'alto', 'tenor', 'bass', 'percussion', 'treble_8', 'bass_8', 'baritone'] @@ -1151,61 +1186,54 @@ class Etf_file: def identify(): sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version)) -def help (): - sys.stdout.write("""Usage: etf2ly [OPTIONS]... ETF-FILE - -Convert ETF to LilyPond. - -Options: - -h, --help print this help - -o, --output=FILE set output filename to FILE - -v, --version show version information - -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. - -Report bugs via - - http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs +def warranty (): + identify () + sys.stdout.write (''' +Copyright (c) %s by -Written by Han-Wen Nienhuys . + Han-Wen Nienhuys + Jan Nieuwenhuizen -""") +%s +%s +''' % ( '2001--2006', + _('Distributed under terms of the GNU General Public License.'), + _('It comes with NO WARRANTY.'))) -def print_version (): - sys.stdout.write (r"""etf2ly (GNU lilypond) %s -This is free software. It is covered by the GNU General Public License, -and you are welcome to change it and/or distribute copies of it under -certain conditions. Invoke as `midi2ly --warranty' for more information. -Copyright (c) 2000--2006 by Han-Wen Nienhuys -""" % version) - - - -(options, files) = getopt.getopt (sys.argv[1:], 'vo:h', ['help','version', 'output=']) -out_filename = None - -for opt in options: - o = opt[0] - a = opt[1] - if o== '--help' or o == '-h': - help () +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"), + metavar=_("FILE"), + action='store') + p.add_option ('-w', '--warranty', help=_ ("show warranty"), + 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''') + return p + +def do_options (): + opt_parser = get_option_parser() + (options,args) = opt_parser.parse_args () + if options.warranty: + warranty () sys.exit (0) - if o == '--version' or o == '-v': - print_version () - sys.exit(0) - - if o == '--output' or o == '-o': - out_filename = a - else: - print o - raise getopt.error + return (options,args) + +(options, files) = do_options() identify() +out_filename = options.output + e = None for f in files: if f == '-': diff --git a/scripts/midi2ly.py b/scripts/midi2ly.py index 7e0ad8f7c9..31ce07caaa 100644 --- a/scripts/midi2ly.py +++ b/scripts/midi2ly.py @@ -104,15 +104,18 @@ def identify (): def warranty (): identify () - sys.stdout.write ('\n') - sys.stdout.write (_ ('Copyright (c) %s by') % ' 2001--2006') - sys.stdout.write ('\n') - sys.stdout.write (' Han-Wen Nienhuys\n') - sys.stdout.write (' Jan Nieuwenhuizen\n') - sys.stdout.write ('\n\n') - sys.stdout.write (_ ("Distributed under terms of the GNU General Public License.") + '\n') - sys.stdout.write (_ ("It comes with NO WARRANTY.") + '\n') - sys.stdout.write ('\n') + sys.stdout.write (''' +Copyright (c) %s by + + Han-Wen Nienhuys + Jan Nieuwenhuizen + +%s +%s +''' ( '2001--2006', + _('Distributed under terms of the GNU General Public License.'), + _('It comes with NO WARRANTY.')) + def progress (s): errorport.write (s + '\n')