]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/lilylib.py
* Another grand 2003 update.
[lilypond.git] / python / lilylib.py
index d9250f0807ad0079c94bbb385c55ea6750107a23..67485321f750dc4b9765cb0f7c95aad922f9a16c 100644 (file)
@@ -3,7 +3,7 @@
 # 
 # source file of the GNU LilyPond music typesetter
 #
-# (c) 1998--2002  Han-Wen Nienhuys <hanwen@cs.uu.nl>
+# (c)  1998--2003  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\) *(
@@ -39,6 +39,8 @@ if os.environ.has_key ('LILYPONDPREFIX') :
 
 sys.path.insert (0, os.path.join (datadir, 'python'))
 
+
+
 # Customize these
 if __name__ == '__main__':
        import lilylib as ly
@@ -86,6 +88,7 @@ try:
 except:
        pass
 
+localedir = '@localedir@'
 try:
        import gettext
        gettext.bindtextdomain ('lilypond', localedir)
@@ -98,7 +101,7 @@ underscore = _
 
 program_version = '@TOPLEVEL_VERSION@'
 if program_version == '@' + 'TOPLEVEL_VERSION' + '@':
-       program_version = '1.7.5'
+       program_version = '1.7.14'
 
 def identify (port):
        port.write ('%s (GNU LilyPond) %s\n' % (__main__.program_name, program_version))
@@ -106,7 +109,7 @@ def identify (port):
 def warranty ():
        identify (sys.stdout)
        sys.stdout.write ('\n')
-       sys.stdout.write (_ ('Copyright (c) %s by' % ' 1998--2002'))
+       sys.stdout.write (_ ('Copyright (c) %s by' % ' 1998--2003'))
        sys.stdout.write ('\n')
        map (lambda x: sys.stdout.write ('  %s\n' % x), __main__.copyright)
        sys.stdout.write ('\n')
@@ -119,10 +122,10 @@ def progress (s):
        sys.stderr.write (s)
 
 def warning (s):
-       sys.stderr.write (__main__.program_name + ":" + _ ("warning: ") + s + '\n')
+       sys.stderr.write (__main__.program_name + ": " + _ ("warning: ") + s + '\n')
 
 def error (s):
-       sys.stderr.write (__main__.program_name + ":" + _ ("error: ") + s + '\n')
+       sys.stderr.write (__main__.program_name + ": " + _ ("error: ") + s + '\n')
        
 def exit (i):
        if __main__.verbose_p:
@@ -205,7 +208,7 @@ def setup_temp ():
        if not __main__.keep_temp_dir_p:
                __main__.temp_dir = tempfile.mktemp (__main__.program_name)
        try:
-               os.mkdir (__main__.temp_dir, 0777)
+               os.mkdir (__main__.temp_dir, 0700)
        except OSError:
                pass
 
@@ -269,7 +272,12 @@ Exit status of CMD '''
        exit_status = status >> 8
        
        if status:
-               msg = _ ("`%s\' failed (%d)") % (name, exit_status)
+               
+               exit_type =  'status %d' % exit_status
+               if signal:
+                       exit_type = 'signal %d' % signal 
+               
+               msg = _ ("`%s\' failed (%s)") % (name, exit_type)
                if ignore_error:
                        if __main__.verbose_p:
                                warning (msg + ' ' + _ ("(ignored)"))
@@ -374,15 +382,11 @@ def print_environment ():
                sys.stderr.write ("%s=\"%s\"\n" % (k, v)) 
 
 def get_bbox (filename):
-       ####system ('gs -sDEVICE=bbox -q  -sOutputFile=- -dNOPAUSE %s -c quit > %s.bbox 2>&1 ' % (filename, filename))
-       #### FIXME: 2>&1 ? --jcn
        bbox = filename + '.bbox'
        ## -sOutputFile does not work with bbox?
-       ##cmd = 'gs -sDEVICE=bbox -q -sOutputFile=%s -dNOPAUSE %s -c quit' % \
-       ##      (bbox, filename)
        cmd = 'gs -sDEVICE=bbox -q -dNOPAUSE %s -c quit 2>%s' % \
              (filename, bbox)
-       system (cmd)
+       system (cmd, progress_p = 1)
        box = open (bbox).read ()
        m = re.match ('^%%BoundingBox: ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)',
                      box)
@@ -398,7 +402,6 @@ def make_preview (name):
        if not os.path.isfile (preview_ps):
                preview_ps = name + '.eps'
        bbox = get_bbox (preview_ps)
-       print 'bbox:' + `bbox`
        trans_ps = name + '.trans.ps'
        png = name + '.png'
        
@@ -420,8 +423,6 @@ def make_preview (name):
        cmd = r'''gs -g%dx%d -sDEVICE=pnggray  -dTextAlphaBits=4 -dGraphicsAlphaBits=4  -q -sOutputFile=%s -r%d -dNOPAUSE %s %s -c quit ''' % \
              (x, y, png, __main__.preview_resolution, trans_ps, preview_ps)
        
-       system (cmd)
-
        status = system (cmd)
        signal = 0xf & status
        exit_status = status >> 8
@@ -430,3 +431,14 @@ def make_preview (name):
                os.unlink (png)
                error (_ ("Removing output file"))
                exit (1)
+
+def make_page_images (name, resolution = 90):
+
+       """ Generate images for
+       all pages in the PS file NAME. NAME should be the basename
+       (not including the extension.).
+       """
+       
+       cmd = 'gs -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="%s-page%%d.png" -r%d -dNOPAUSE %s -c quit'
+       cmd = cmd % (name, resolution, name + '.ps')
+       system (cmd)