-def progress (s):
- '''Make the progress messages stand out between lilypond stuff'''
- # Why should they have to stand out? Blend in would be nice too.
- sys.stderr.write ('*** ' + s+ '\n')
-
-def error (s):
- sys.stderr.write (s)
- raise _ ("Exiting ... ")
-
-
-def find_file (name):
- '''
- Search the include path for NAME. If found, return the (CONTENTS, PATH) of the file.
- '''
-
- f = None
- nm = ''
- for a in include_path:
- try:
- nm = os.path.join (a, name)
- f = open (nm)
- __main__.read_files.append (nm)
- break
- except IOError:
- pass
- if f:
- sys.stderr.write (_ ("Reading `%s'") % nm)
- sys.stderr.write ('\n');
- return (f.read (), nm)
- else:
- error (_ ("can't open file: `%s'" % name))
- sys.stderr.write ('\n');
- return ('', '')
-
-
-
-
-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") % 'ly2dvi')
- sys.stdout.write ('\n\n')
- sys.stdout.write (_ ("Generate .dvi with LaTeX for LilyPond"))
- 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\n')
- sys.stdout.write (_ ("warning: "))
- sys.stdout.write (_ ("all output is written in the CURRENT directory"))
- sys.stdout.write ('\n\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
- temp_dir = 'ly2dvi.dir'
- if not keep_temp_dir:
- temp_dir = tempfile.mktemp ('ly2dvi')
-
- try:
- os.mkdir (temp_dir, 0777)
- except OSError:
- pass
-
-
- # try not to gen/search MF stuff in temp dir
- fp = ''
- try:
- fp = ':' + os.environ['TFMFONTS']
- except KeyError:
- fp = '://:'