-def identify (port):
- port.write ('%s (GNU LilyPond) %s\n' % (__main__.program_name, __main__.program_version))
-
-def warranty ():
- identify (sys.stdout)
- sys.stdout.write ('\n')
- sys.stdout.write (_ ("Copyright (c) %s by") % '1998--2004')
- sys.stdout.write ('\n')
- map (lambda x: sys.stdout.write (' %s\n' % x), __main__.copyright)
- sys.stdout.write ('\n')
- sys.stdout.write (_ ("Distributed under terms of the GNU General Public License."))
- sys.stdout.write ('\n')
- sys.stdout.write (_ ("It comes with NO WARRANTY."))
- sys.stdout.write ('\n')
-
-def progress (s):
- sys.stderr.write (s)
-
-def warning (s):
- sys.stderr.write (__main__.program_name + ": " + _ ("warning: %s") % s + '\n')
-
-def error (s):
- sys.stderr.write (__main__.program_name + ": " + _ ("error: %s") % s + '\n')
-
-def exit (i):
- if __main__.verbose_p:
- raise _ ('Exiting (%d)...') % i
- else:
- sys.exit (1)
-
-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 ():
- ls = [(_ ("Usage: %s [OPTIONS]... FILE") % __main__.program_name),
- ('\n\n'),
- (__main__.help_summary),
- ('\n\n'),
- (_ ("Options:")),
- ('\n'),
- (options_help_str (__main__.option_definitions)),
- ('\n\n'),
- (_ ("Report bugs to %s.") % 'bug-lilypond@gnu.org'),
- ('\n')]
- map (sys.stdout.write, ls)
-
-def lilypond_version (binary):
- p = read_pipe ('%s --version ' % binary)
-
- ls = p.split ('\n')
- v= '<not found>'
- for l in ls:
- m = re.search ('GNU LilyPond ([0-9a-z.]+)', p)
- if m:
- v = m.group (1)
-
- return v
-
-def lilypond_version_check (binary, req):
- if req[0] <> '@' :
- v = lilypond_version (binary)
- if v <> req:
- error (_("Binary %s has version %s, looking for version %s") % \
- (binary, v, req))
- sys.exit (1)
-
-
-def setup_temp ():
-
- ''' Create a temporary directory, and return its name. '''
-
- if not __main__.keep_temp_dir_p:
- __main__.temp_dir = tempfile.mktemp (__main__.program_name)
- try:
- os.mkdir (__main__.temp_dir, 0700)
- except OSError:
- pass
-
- return __main__.temp_dir
+# Urg, Python 2.4 does not define stderr/stdout encoding
+# Maybe guess encoding from LANG/LC_ALL/LC_CTYPE?
+
+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)
+
+progress = stderr_write
+
+def require_python_version ():
+ if sys.hexversion < 0x02040000:
+ stderr_write ("Python 2.4 or newer is required to run this program.\n\
+Please upgrade Python from http://python.org/download/, and if you use MacOS X,\n\
+please read 'Setup for MacOS X' in Application Usage.")
+ os.system ("open http://python.org/download/")
+ sys.exit (2)
+
+# Modified version of the commands.mkarg(x), which always uses
+# double quotes (since Windows can't handle the single quotes:
+def mkarg(x):
+ s = ' "'
+ for c in x:
+ if c in '\\$"`':
+ s = s + '\\'
+ s = s + c
+ s = s + '"'
+ return s