1 # lilylib.py -- options and stuff
3 # source file of the GNU LilyPond music typesetter
10 gettext.bindtextdomain ('lilypond', '@localedir@')
11 gettext.textdomain ('lilypond')
17 program_version = '@TOPLEVEL_VERSION@'
18 if program_version == '@' + 'TOPLEVEL_VERSION' + '@':
19 program_version = '1.5.17'
22 original_dir = os.getcwd ()
23 temp_dir = os.path.join (original_dir, '%s.dir' % program_name)
25 errorport = sys.stderr
31 sys.stdout.write ('%s (GNU LilyPond) %s\n' % (program_name, program_version))
35 sys.stdout.write ('\n')
36 sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001'))
37 sys.stdout.write ('\n')
38 sys.stdout.write (' Han-Wen Nienhuys')
39 sys.stdout.write (' Jan Nieuwenhuizen')
40 sys.stdout.write ('\n')
41 sys.stdout.write (_ (r'''
42 Distributed under terms of the GNU General Public License. It comes with
44 sys.stdout.write ('\n')
47 errorport.write (s + '\n')
50 progress (_ ("warning: ") + s)
55 '''Report the error S. Exit by raising an exception. Please
56 do not abuse by trying to catch this error. If you do not want
57 a stack trace, write to the output directly.
65 progress (_ ("error: ") + s)
66 raise _ ("Exiting ... ")
68 def getopt_args (opts):
69 '''Construct arguments (LONG, SHORT) for getopt from list of options.'''
84 def option_help_str (o):
85 '''Transform one option description (4-tuple ) into neatly formatted string'''
103 return ' ' + sh + sep + long + arg
106 def options_help_str (opts):
107 '''Convert a list of options into a neatly formatted string'''
113 s = option_help_str (o)
114 strs.append ((s, o[3]))
120 str = str + '%s%s%s\n' % (s[0], ' ' * (w - len(s[0]) + 3), s[1])
124 ls = [(_ ("Usage: %s [OPTION]... FILE") % program_name),
130 (options_help_str (option_definitions)),
132 (_ ("Report bugs to %s") % 'bug-lilypond@gnu.org'),
134 map (sys.stdout.write, ls)
138 Create a temporary directory, and return its name.
141 if not keep_temp_dir_p:
142 temp_dir = tempfile.mktemp (program_name)
144 os.mkdir (temp_dir, 0777)
151 def system (cmd, ignore_error = 0):
152 """Run CMD. If IGNORE_ERROR is set, don't complain when CMD returns non zero.
160 progress (_ ("Invoking `%s\'") % cmd)
163 name = re.match ('[ \t]*([^ \t]*)', cmd).group (1)
164 msg = name + ': ' + _ ("command exited with value %d") % st
166 warning (msg + ' ' + _ ("(ignored)") + ' ')
174 if not keep_temp_dir_p:
176 progress (_ ("Cleaning %s...") % temp_dir)
177 shutil.rmtree (temp_dir)
181 def set_setting (dict, key, val):
183 val = string.atof (val)
185 #warning (_ ("invalid value: %s") % `val`)
189 dict[key].append (val)
191 warning (_ ("no such setting: %s") % `key`)
195 def strip_extension (f, ext):
196 (p, e) = os.path.splitext (f)