1 # lilylib.py -- options and stuff
3 # source file of the GNU LilyPond music typesetter
9 gettext
.bindtextdomain ('lilypond', localedir
)
10 gettext
.textdomain ('lilypond')
16 if program_version
== '@' + 'TOPLEVEL_VERSION' + '@':
17 program_version
= '1.5.17'
20 sys
.stdout
.write ('%s (GNU LilyPond) %s\n' % (program_name
, program_version
))
24 sys
.stdout
.write ('\n')
25 sys
.stdout
.write (_ ('Copyright (c) %s by' % ' 2001'))
26 sys
.stdout
.write ('\n')
27 sys
.stdout
.write (' Han-Wen Nienhuys')
28 sys
.stdout
.write (' Jan Nieuwenhuizen')
29 sys
.stdout
.write ('\n')
30 sys
.stdout
.write (_ (r
'''
31 Distributed under terms of the GNU General Public License. It comes with
33 sys
.stdout
.write ('\n')
36 errorport
.write (s
+ '\n')
39 progress (_ ("warning: ") + s
)
44 '''Report the error S. Exit by raising an exception. Please
45 do not abuse by trying to catch this error. If you do not want
46 a stack trace, write to the output directly.
54 progress (_ ("error: ") + s
)
55 raise _ ("Exiting ... ")
57 def getopt_args (opts
):
58 '''Construct arguments (LONG, SHORT) for getopt from list of options.'''
73 def option_help_str (o
):
74 '''Transform one option description (4-tuple ) into neatly formatted string'''
92 return ' ' + sh
+ sep
+ long + arg
95 def options_help_str (opts
):
96 '''Convert a list of options into a neatly formatted string'''
102 s
= option_help_str (o
)
103 strs
.append ((s
, o
[3]))
109 str = str + '%s%s%s\n' % (s
[0], ' ' * (w
- len(s
[0]) + 3), s
[1])
113 ls
= [(_ ("Usage: %s [OPTION]... FILE") % program_name
),
119 (options_help_str (option_definitions
)),
121 (_ ("Report bugs to %s") % 'bug-lilypond@gnu.org'),
123 map (sys
.stdout
.write
, ls
)
127 Create a temporary directory, and return its name.
130 if not keep_temp_dir_p
:
131 temp_dir
= tempfile
.mktemp (program_name
)
133 os
.mkdir (temp_dir
, 0777)
140 def system (cmd
, ignore_error
= 0):
141 """Run CMD. If IGNORE_ERROR is set, don't complain when CMD returns non zero.
149 progress (_ ("Invoking `%s\'") % cmd
)
152 name
= re
.match ('[ \t]*([^ \t]*)', cmd
).group (1)
153 msg
= name
+ ': ' + _ ("command exited with value %d") % st
155 warning (msg
+ ' ' + _ ("(ignored)") + ' ')
163 if not keep_temp_dir_p
:
165 progress (_ ("Cleaning %s...") % temp_dir
)
166 shutil
.rmtree (temp_dir
)
169 def strip_extension (f
, ext
):
170 (p
, e
) = os
.path
.splitext (f
)