1 ###############################################################
2 # lilylib.py -- options and stuff
4 # source file of the GNU LilyPond music typesetter
6 # (c) 1998--2006 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 # Jan Nieuwenhuizen <janneke@gnu.org>
19 ## windows mingw cross compile doesn't have selectmodule.so
26 ################################################################
27 # Users of python modules should include this snippet
28 # and customize variables below.
30 # We'll suffer this path init stuff as long as we don't install our
31 # python packages in <prefix>/lib/pythonx.y (and don't kludge around
32 # it as we do with teTeX on Red Hat Linux: set some environment var
33 # (PYTHONPATH) in profile)
35 # If set, LILYPONDPREFIX must take prevalence
36 # if datadir is not set, we're doing a build and LILYPONDPREFIX
38 datadir = '@local_lilypond_datadir@'
39 if not os.path.isdir (datadir):
40 datadir = '@lilypond_datadir@'
41 if os.environ.has_key ('LILYPONDPREFIX') :
42 datadir = os.environ['LILYPONDPREFIX']
43 while datadir[-1] == os.sep:
46 sys.path.insert (0, os.path.join (datadir, 'python'))
51 localedir = '@localedir@'
54 gettext.bindtextdomain ('lilypond', localedir)
55 gettext.textdomain ('lilypond')
61 progress = sys.stderr.write
64 def command_name (cmd):
65 # Strip all stuf after command,
66 # deal with "((latex ) >& 1 ) .." too
67 cmd = re.match ('([\(\)]*)([^\\\ ]*)', cmd).group (2)
68 return os.path.basename (cmd)
76 show_progress= progress_p
77 name = command_name (cmd)
82 progress (_ ("Invoking `%s\'") % cmd)
84 progress ( _("Running %s...") % name)
89 stdout_setting = subprocess.PIPE
91 proc = subprocess.Popen (cmd,
93 universal_newlines=True,
94 stdout=stdout_setting,
95 stderr=stdout_setting)
102 log = proc.communicate ()
103 retval = proc.returncode
107 print >>sys.stderr, 'command failed:', cmd
109 print >>sys.stderr, "Child was terminated by signal", -retval
111 print >>sys.stderr, "Child returned", retval
114 print >>sys.stderr, "Error ignored"
116 if not show_progress:
123 def strip_extension (f, ext):
124 (p, e) = os.path.splitext (f)
130 def search_exe_path (name):
131 p = os.environ['PATH']
132 exe_paths = string.split (p, ':')
134 full = os.path.join (e, name)
135 if os.path.exists (full):
140 def print_environment ():
141 for (k,v) in os.environ.items ():
142 sys.stderr.write ("%s=\"%s\"\n" % (k, v))
145 class NonDentedHeadingFormatter (optparse.IndentedHelpFormatter):
146 def format_heading(self, heading):
148 return heading[0].upper() + heading[1:] + ':\n'
150 def format_option_strings(self, option):
152 if option._short_opts and option._long_opts:
156 if option.takes_value():
157 metavar = '=%s' % option.metavar or option.dest.upper()
159 return "%3s%s %s%s" % (" ".join (option._short_opts),
161 " ".join (option._long_opts),
164 def format_usage(self, usage):
165 return _("Usage: %s\n") % usage
167 def format_description(self, description):
170 def get_option_parser (*args, **kwargs):
171 p = optparse.OptionParser (*args, **kwargs)
172 p.formatter = NonDentedHeadingFormatter ()