# If set, LILYPONDPREFIX must take prevalence
# if datadir is not set, we're doing a build and LILYPONDPREFIX
-import getopt, os, sys
+import getopt
+import os
+import sys
datadir = '@local_lilypond_datadir@'
if not os.path.isdir (datadir):
datadir = '@lilypond_datadir@'
if __main__.verbose_p:
raise _ ('Exiting (%d)...') % i
else:
- sys.exit (1)
+ sys.exit (i)
def getopt_args (opts):
'''Construct arguments (LONG, SHORT) for getopt from list of options.'''
def command_name (cmd):
- # deal with "((latex ) >& 1 ) .." too
+ # deal with "((latex ) >& 1 ) .." too
cmd = re.match ("([\(\)]*)([^ ]*)", cmd).group(2)
- return os.path.split (cmd)[1]
+ return os.path.basename (cmd)
def error_log (name):
name = re.sub('[^a-z]','x', name)
if error_log_file:
os.unlink (error_log_file)
- exit (status)
+ exit (1)
if __main__.verbose_p:
progress ('\n')
sys.stderr.write (open (error_log_file).read ())
if error_log_file:
os.unlink (error_log_file)
- exit (status)
+ exit (1)
if error_log_file:
os.unlink (error_log_file)
for (k,v) in os.environ.items ():
sys.stderr.write ("%s=\"%s\"\n" % (k, v))
+BOUNDING_BOX_RE = '^%%BoundingBox: (-?[0-9]+) (-?[0-9]+) (-?[0-9]+) (-?[0-9]+)'
def get_bbox (filename):
bbox = filename + '.bbox'
## -sOutputFile does not work with bbox?
(filename, bbox)
system (cmd, progress_p = 1)
box = open (bbox).read ()
- m = re.match ('^%%BoundingBox: ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)',
- box)
+ m = re.match (BOUNDING_BOX_RE, box)
gr = []
if m:
gr = map (string.atoi, m.groups ())
base = re.sub (r'\.e?ps', '', ps_name)
header = open (ps_name).read (1024)
+
+ match = re.match (BOUNDING_BOX_RE, header)
+ bbox = []
+ if match:
+ bbox = map (string.atoi, match.groups ())
+
multi_page = re.search ('\n%%Pages: ', header)
cmd = ''
if multi_page == None:
- bbox = get_bbox (ps_name)
+
+ if bbox == []:
+ bbox = get_bbox (ps_name)
+
trans_ps = ps_name + '.trans.ps'
output_file = re.sub (r'\.e?ps', '.png', ps_name)
-
-
# need to have margin, otherwise edges of letters will
# be cropped off.
os.unlink (png)
error (_ ("Removing output file"))
exit (1)
+
+
+ cmd = r'''gs -s -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -dNOPAUSE -r%d %s -c quit''' % (output_file,
+ resolution, ps_name)
+
+ return output_file
+