import string
import sys
import tempfile
+import glob
################################################################
# Users of python modules should include this snippet
# If set, LILYPONDPREFIX must take prevalence
# if datadir is not set, we're doing a build and LILYPONDPREFIX
+
import getopt, os, sys
datadir = '@local_lilypond_datadir@'
if not os.path.isdir (datadir):
help_summary = _ ("lilylib module")
option_definitions = [
- ('', 'h', 'help', _ ("this help")),
+ ('', 'h', 'help', _ ("print this help")),
]
from lilylib import *
return s
underscore = _
-program_version = '@TOPLEVEL_VERSION@'
-if program_version == '@' + 'TOPLEVEL_VERSION' + '@':
- program_version = '1.7.14'
-
def identify (port):
- port.write ('%s (GNU LilyPond) %s\n' % (__main__.program_name, program_version))
+ port.write ('%s (GNU LilyPond) %s\n' % (__main__.program_name, __main__.program_version))
def warranty ():
identify (sys.stdout)
('\n'),
(options_help_str (__main__.option_definitions)),
('\n\n'),
- (_ ("Report bugs to %s") % 'bug-lilypond@gnu.org'),
+ (_ ("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 ():
return re.match ('^[ \t]*([^ \t]*)', cmd).group (1)
def error_log (name):
- return os.path.join (__main__.temp_dir, '%s.errorlog' % name)
+ name = re.sub('[/:]','x',name)
+ return tempfile.mktemp ('%s.errorlog' % name)
def read_pipe (cmd, mode = 'r'):
redirect = ''
+ error_log_file = ''
if __main__.verbose_p:
progress (_ ("Opening pipe `%s\'") % cmd)
- redirect = ' 2>%s' % error_log (command_name (cmd))
+ error_log_file = error_log (command_name (cmd))
+ redirect = ' 2>%s' % error_log_file
+
pipe = os.popen (cmd + redirect, mode)
output = pipe.read ()
status = pipe.close ()
error (_ ("The error log is as follows:"))
sys.stderr.write (open (error_log (command_name (cmd)).read ()))
exit (status)
+
if __main__.verbose_p:
progress ('\n')
+
+ if error_log_file:
+ os.unlink (error_log_file)
+
return output
def system (cmd, ignore_error = 0, progress_p = 0):
def cp_to_dir (pattern, dir):
"Copy files matching re PATTERN from cwd to DIR"
+
# Duh. Python style portable: cp *.EXT OUTDIR
# system ('cp *.%s %s' % (ext, outdir), 1)
+
files = filter (lambda x, p=pattern: re.match (p, x), os.listdir ('.'))
map (lambda x, d=dir: shutil.copy2 (x, os.path.join (d, x)), files)
#
# On most platforms, this is equivalent to
#`normpath(join(os.getcwd()), PATH)'. *Added in Python version 1.5.2*
+
if os.path.__dict__.has_key ('abspath'):
abspath = os.path.abspath
else:
# * clean TEXINPUTS, MFINPUTS, TFMFONTS,
# as these take prevalence over $TEXMF
# and thus may break tex run?
+
'TEXMF' : "{%s,%s}" % (datadir, texmf) ,
'GS_FONTPATH' : type1_paths,
'GS_LIB' : datadir + '/ps',
cmd = r'''gs -g%dx%d -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -r%d -dNOPAUSE %s %s -c quit ''' % \
(x, y, output_file, resolution, trans_ps, ps_name)
- rmfile = base + '-page*.png'
+ rms = glob.glob (base + '-page*.png')
+ map (os.unlink, rms)
else:
output_file = re.sub (r'\.e?ps', '-page%d.png', ps_name)
rmfile = base + '.png'
-
+ if os.path.isfile (rmfile):
+ os.unlink (rmfile)
+
cmd = r'''gs -s -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -dNOPAUSE -r%d %s -c quit''' % (output_file,
resolution, ps_name)
signal = 0xf & status
exit_status = status >> 8
- rms = glob.glob (rmfile)
- print 'removing ', rms
- map (os.unlink, rms)
if status:
os.unlink (png)