def encoded_write(f, s):
f.write (s.encode (f.encoding or 'utf_8'))
+# ugh, Python 2.5 optparse requires Unicode strings in some argument
+# functions, and refuse them in some other places
+def display_encode (s):
+ return s.encode (sys.stderr.encoding or 'utf_8')
+
def stderr_write (s):
encoded_write (sys.stderr, s)
import sys
import string
import re
+import lilylib
+
+_ = lilylib._
from rational import Rational
previous_pitch = None
relative_pitches = False
+def warning (str):
+ ly.stderr_write ((_ ("warning: %s") % str) + "\n")
+
+
def escape_instrument_string (input_string):
retstring = string.replace (input_string, "\"", "\\\"")
if re.match ('.*[\r\n]+.*', retstring):
self.music = SequentialMusic ()
self.music.elements = music
else:
- sys.stderr.write (_ ("WARNING: Unable to set the music %s for the repeat %s" % (music, self)))
+ warning (_ ("unable to set the music %(music)s for the repeat %(repeat)s" % \
+ {'music':music, 'repeat':self}))
def add_ending (self, music):
self.endings.append (music)
def print_ly (self, printer):
if self.music:
self.music.print_ly (printer)
else:
- sys.stderr.write (_ ("WARNING: Encountered repeat without body\n"))
+ warning (_ ("encountered repeat without body"))
printer.dump ('{}')
if self.endings:
printer.dump ('\\alternative {')
import re
import sys
import copy
+import lilylib
+
+_ = lilylib._
+
+def error (str):
+ ly.stderr_write ((_ ("error: %s") % str) + "\n")
+
def escape_ly_output_string (input_string):
return_string = input_string
else:
return (4, 4)
except KeyError:
- sys.stderr.write (_ ("error: requested time signature, but time sig is unknown\n"))
+ error (_ ("requested time signature, but time sig is unknown"))
return (4, 4)
# returns clef information in the form ("cleftype", position, octave-shift)
if instrument_name:
return instrument_name
else:
- sys.stderr.write (_ ("Unable to find find instrument for ID=%s\n") % id)
+ lilylib.stderr_write (_ ("Unable to find find instrument for ID=%s\n") % id)
return "Grand Piano"
class Part_group (Music_xml_node):
def get_option_parser ():
p = ly.get_option_parser (usage=_ ("%s [OPTION]... FILE") % 'abc2ly',
- version="abc2ly (LilyPond) @TOPLEVEL_VERSION@",
description=_ ('''abc2ly converts ABC music files (see
-%s) to LilyPond input.''') % 'http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt')
+%s) to LilyPond input.''') % 'http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt',
+ add_help_option=False)
+ p.version = "abc2ly (LilyPond) @TOPLEVEL_VERSION@"
+ p.add_option("--version",
+ action="version",
+ help=_ ("show version number and exit"))
+
+ p.add_option("-h", "--help",
+ action="help",
+ help=_ ("show this help and exit"))
p.add_option ('-o', '--output', metavar='FILE',
help=_ ("write output to FILE"),
action='store')
p.add_option ('-s', '--strict', help=_ ("be strict about succes"),
action='store_true')
p.add_option ('-b', '--beams', help=_ ("preserve ABC's notion of beams"))
- p.add_option_group ('bugs',
+ p.add_option_group (ly.display_encode (_ ('Bugs')),
description=(_ ('Report bugs via')
+ ''' http://post.gmane.org/post.php'''
'''?group=gmane.comp.gnu.lilypond.bugs\n'''))
def get_option_parser ():
p = ly.get_option_parser (usage=_ ("%s [OPTION]... FILE") % 'convert-ly',
- version="@TOPLEVEL_VERSION@",
- description=help_summary)
+ description=help_summary,
+ add_help_option=False)
+
+ p.version="@TOPLEVEL_VERSION@"
+ p.add_option("--version",
+ action="version",
+ help=_ ("show version number and exit"))
+
+ p.add_option("-h", "--help",
+ action="help",
+ help=_ ("show this help and exit"))
p.add_option ('-f', '--from',
action="store",
dest="to_version",
default='')
- p.add_option_group ('bugs',
+ p.add_option_group (ly.display_encode (_ ('Bugs')),
description=(_ ("Report bugs via")
+ ''' http://post.gmane.org/post.php'''
'''?group=gmane.comp.gnu.lilypond.bugs\n'''))
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')
action='store_true',
),
- p.add_option_group ('bugs',
+ p.add_option_group (ly.display_encode (_ ('Bugs')),
description=(_ ('Report bugs via')
+ ''' http://post.gmane.org/post.php'''
'''?group=gmane.comp.gnu.lilypond.bugs\n'''))
def get_option_parser ():
p = ly.get_option_parser (usage=_ ("%s [OPTION]... FILE") % 'lilypond-book',
- version="@TOPLEVEL_VERSION@",
- description=help_summary)
+ description=help_summary,
+ add_help_option=False)
p.add_option ('-F', '--filter', metavar=_ ("FILTER"),
action="store",
dest="filter_cmd",
help=_ ("pipe snippets through FILTER [convert-ly -n -]"),
default=None)
+
p.add_option ('-f', '--format',
help=_ ("use output format FORMAT (texi [default], texi-html, latex, html, docbook)"),
action='store')
-
+
+ p.add_option("-h", "--help",
+ action="help",
+ help=_ ("show this help and exit"))
+
p.add_option ("-I", '--include', help=_ ("add DIR to include path"),
metavar=_ ("DIR"),
action='append', dest='include_path',
default=[os.path.abspath (os.getcwd ())])
- p.add_option ('--info-images-dir', help=_ ("format Texinfo output so that Info will "
- "look for images of music in DIR"),
+ p.add_option ('--info-images-dir',
+ help=_ ("format Texinfo output so that Info will "
+ "look for images of music in DIR"),
metavar=_ ("DIR"),
action='store', dest='info_images_dir',
default='')
help = _ ("process ly_files using COMMAND FILE..."),
action='store',
dest='process_cmd', default='lilypond -dbackend=eps')
+
p.add_option ('--pdf',
action="store_true",
dest="create_pdf",
help=_ ("create PDF files for use with PDFTeX"),
default=False)
+
p.add_option ('', '--psfonts', action="store_true", dest="psfonts",
help=_ ('''extract all PostScript fonts into INPUT.psfonts for LaTeX
must use this with dvips -h INPUT.psfonts'''),
default=None)
+
p.add_option ('-V', '--verbose', help=_ ("be verbose"),
action="store_true",
default=False,
dest="verbose")
+
+ p.version = "@TOPLEVEL_VERSION@"
+ p.add_option("--version",
+ action="version",
+ help=_ ("show version number and exit"))
+
p.add_option ('-w', '--warranty',
help=_ ("show warranty and copyright"),
action='store_true')
- p.add_option_group (_ ('Bugs'),
+ p.add_option_group (ly.display_encode (_ ('Bugs')),
description=(_ ("Report bugs via")
+ ''' http://post.gmane.org/post.php'''
'''?group=gmane.comp.gnu.lilypond.bugs\n'''))
def get_option_parser ():
p = ly.get_option_parser (usage=_ ("%s [OPTION]... FILE") % 'midi2ly',
- version="midi2ly (LilyPond) @TOPLEVEL_VERSION@",
- description=_ ("Convert %s to LilyPond input.") % 'MIDI')
+ description=_ ("Convert %s to LilyPond input.") % 'MIDI',
+ add_help_option=False)
p.add_option ('-a', '--absolute-pitches',
action='store_true',
p.add_option ('-e', '--explicit-durations',
action='store_true',
help=_ ("print explicit durations"))
+ p.add_option("-h", "--help",
+ action="help",
+ help=_ ("show this help and exit"))
p.add_option('-k', '--key', help=_ ("set key: ALT=+sharps|-flats; MINOR=1"),
metavar=_ ("ALT[:MINOR]"),
default='0'),
p.add_option ('-V', '--verbose', help=_ ("be verbose"),
action='store_true'
),
+ p.version = "midi2ly (LilyPond) @TOPLEVEL_VERSION@"
+ p.add_option("--version",
+ action="version",
+ help=_ ("show version number and exit"))
p.add_option ('-w', '--warranty', help=_ ("show warranty and copyright"),
action='store_true',
),
p.add_option ('-x', '--text-lyrics', help=_ ("treat every text as a lyric"),
action='store_true')
-# urg, Python 2.5 optparse is broken, it doesn't accept Unicode strings
- p.add_option_group (_ ("Examples").encode (sys.stdout.encoding),
+ p.add_option_group (ly.display_encode (_ ("Examples")),
description = r'''
midi2ly --key=-2:1 --duration-quant=32 \
--allow-tuplet=4*2/3 --allow-tuplet=2*4/3 foo.midi
''')
- p.add_option_group (_ ('Bugs').encode (sys.stdout.encoding),
+ p.add_option_group (ly.display_encode (_ ('Bugs')),
description=(_ ('Report bugs via')
+ ''' http://post.gmane.org/post.php'''
'''?group=gmane.comp.gnu.lilypond.bugs\n'''))
import codecs
import zipfile
import StringIO
-from gettext import gettext as _
"""
@relocate-preamble@
"""
import lilylib as ly
+_ = ly._
import musicxml
import musicexp
def option_parser ():
p = ly.get_option_parser (usage = _ ("musicxml2ly [options] FILE.xml"),
- version = ('''%prog (LilyPond) @TOPLEVEL_VERSION@\n\n'''
+ description = _ ("Convert %s to LilyPond input.") % 'MusicXML' + "\n",
+ add_help_option=False)
+
+ p.add_option("-h", "--help",
+ action="help",
+ help=_ ("show this help and exit"))
+
+ p.version = ('''%prog (LilyPond) @TOPLEVEL_VERSION@\n\n'''
+
_ ("""This program 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
Han-Wen Nienhuys <hanwen@xs4all.nl>,
Jan Nieuwenhuizen <janneke@gnu.org> and
Reinhold Kainhofer <reinhold@kainhofer.com>
-"""),
- description = _ ("Convert %s to LilyPond input.") % 'MusicXML' + "\n")
+""")
+ p.add_option("--version",
+ action="version",
+ help=_ ("show version number and exit"))
+
p.add_option ('-v', '--verbose',
action = "store_true",
dest = 'verbose',
action = "store_true",
default = False,
dest = "use_lxml",
- help = _ ("Use lxml.etree; uses less memory and cpu time."))
+ help = _ ("use lxml.etree; uses less memory and cpu time"))
p.add_option ('-z', '--compressed',
action = "store_true",
dest = 'compressed',
default = False,
- help = _ ("Input file is a zip-compressed MusicXML file."))
+ help = _ ("input file is a zip-compressed MusicXML file"))
p.add_option ('-r', '--relative',
action = "store_true",
default = True,
dest = "relative",
- help = _ ("Convert pitches in relative mode. (Default)"))
+ help = _ ("convert pitches in relative mode (default)"))
p.add_option ('-a', '--absolute',
action = "store_false",
dest = "relative",
- help = _ ("Convert pitches in absolute mode."))
+ help = _ ("convert pitches in absolute mode"))
p.add_option ('-l', '--language',
metavar = _ ("LANG"),
action = "store",
- help = _ ("Use a different language file 'LANG.ly' and corresponding pitch names, e.g. 'deutsch' for deutsch.ly."))
+ help = _ ("use a different language file 'LANG.ly' and corresponding pitch names, e.g. 'deutsch' for deutsch.ly"))
p.add_option ('--nd', '--no-articulation-directions',
action = "store_false",
default = True,
dest = "convert_directions",
- help = _ ("Do not convert directions (^, _ or -) for articulations, dynamics, etc."))
+ help = _ ("do not convert directions (^, _ or -) for articulations, dynamics, etc."))
p.add_option ('-o', '--output',
metavar = _ ("FILE"),
type = 'string',
dest = 'output_name',
help = _ ("set output filename to FILE"))
- p.add_option_group ( _ ('Bugs'),
- description = ( _ ("Report bugs via")
+ p.add_option_group (ly.display_encode (_ ('Bugs')),
+ description = (_ ("Report bugs via")
+ ''' http://post.gmane.org/post.php'''
'''?group=gmane.comp.gnu.lilypond.bugs\n'''))
return p