]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/lilylib.py
*** empty log message ***
[lilypond.git] / python / lilylib.py
index df6ee12a6178a0202b7aee3f98a1cd98bcb99ddf..ec72f075f97540789e4b749655a7ae5f71ab87f1 100644 (file)
@@ -3,7 +3,7 @@
 # 
 # source file of the GNU LilyPond music typesetter
 #
-# (c)  1998--200 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+# (c)  1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 #                 Jan Nieuwenhuizen <janneke@gnu.org>
 
 ###  subst:\(^\|[^._a-z]\)\(abspath\|identify\|warranty\|progress\|warning\|error\|exit\|getopt_args\|option_help_str\|options_help_str\|help\|setup_temp\|read_pipe\|system\|cleanup_temp\|strip_extension\|cp_to_dir\|mkdir_p\|init\) *(
@@ -30,7 +30,9 @@ import glob
 # 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@'
@@ -129,7 +131,6 @@ def exit (i):
        if __main__.verbose_p:
                raise _ ('Exiting (%d)...') % i
        else:
-               print 'ex thoto' , i 
                sys.exit (i)
                
 def getopt_args (opts):
@@ -184,7 +185,15 @@ def options_help_str (opts):
 
        str = ''
        for s in strs:
-               str = str + '%s%s%s\n' % (s[0], ' ' * (w - len(s[0])  + 3), s[1])
+               first = 1
+               for ss in re.split ('\n\s*', s[1]):
+                       if first:
+                               str = str + '%s%s%s\n' \
+                                       % (s[0], ' ' * (w - len (s[0]) + 3), ss)
+                               first = 0
+                       else:
+                               str = str + '%s%s\n' \
+                                       % (' ' * (w + 3), ss)
        return str
 
 def help ():
@@ -236,9 +245,9 @@ def setup_temp ():
 
 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)
@@ -412,8 +421,11 @@ def setup_environment ():
                #         and thus may break tex run?
                
                'TEXMF' : "{%s,%s}" % (datadir, texmf) ,
-               'GS_FONTPATH' : type1_paths,
-               'GS_LIB' : datadir + '/ps',
+               
+               # 'GS_FONTPATH' : type1_paths,
+               # 'GS_LIB' : datadir + '/ps',
+               'GS_FONTPATH' : "",
+               'GS_LIB' : "",
                }
        
        # $TEXMF is special, previous value is already taken care of
@@ -438,7 +450,7 @@ 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?
-       cmd = 'gs -sDEVICE=bbox -q -dNOPAUSE %s -c quit 2>%s' % \
+       cmd = 'gs -sDEVICE=bbox -q -dNOPAUSE %s -c showpage -c quit 2>%s' % \
              (filename, bbox)
        system (cmd, progress_p = 1)
        box = open (bbox).read ()
@@ -458,7 +470,7 @@ def make_ps_images (ps_name, resolution = 90):
        
        header = open (ps_name).read (1024)
 
-       match = re.match (BOUNDING_BOX_RE, header)
+       match = re.search (BOUNDING_BOX_RE, header, re.MULTILINE)
        bbox = []
        if match:
                bbox = map (string.atoi, match.groups ())
@@ -492,7 +504,7 @@ def make_ps_images (ps_name, resolution = 90):
                if y == 0:
                        y = 1
 
-               cmd = r'''gs -g%dx%d -sDEVICE=pnggray  -dTextAlphaBits=4 -dGraphicsAlphaBits=4  -q -sOutputFile=%s -r%d -dNOPAUSE %s %s -c quit ''' % \
+               cmd = r'''gs -g%dx%d -sDEVICE=pnggray  -dTextAlphaBits=4 -dGraphicsAlphaBits=4  -q -sOutputFile=%s -r%d -dNOPAUSE %s %s -c showpage -c quit ''' % \
                      (x, y, output_file, resolution, trans_ps, ps_name)
 
                rms = glob.glob (base + '-page*.png')
@@ -504,7 +516,7 @@ def make_ps_images (ps_name, resolution = 90):
                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,
+               cmd = r'''gs -s  -sDEVICE=pnggray  -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -dNOPAUSE -r%d %s -c showpage -c quit''' % (output_file,
                                                                                                                                      resolution, ps_name)
 
        status = system (cmd)
@@ -521,3 +533,6 @@ def make_ps_images (ps_name, resolution = 90):
        cmd = r'''gs -s  -sDEVICE=pnggray  -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -dNOPAUSE -r%d %s -c quit''' % (output_file,
                                                                                                                                      resolution, ps_name)
 
+       files = glob.glob (re.sub ('%d', '*', output_file))
+       return files
+