]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/ly2dvi.py
release: 1.5.43
[lilypond.git] / scripts / ly2dvi.py
index c8ac68ce3cd5fedc72f893cbac15729bbeafffe1..d428202869b5eccf511cac581c4c8c2bba2ef0c9 100644 (file)
@@ -1,4 +1,5 @@
 #!@PYTHON@
+
 # Run lilypond, latex, dvips.
 #
 # This is the third incarnation of ly2dvi.
@@ -14,7 +15,7 @@
 # TODO: should allow to switch off pk cache.
 #
 
-
+#
 # Note: gettext work best if we use ' for docstrings and "
 #       for gettextable strings.
 #       --> DO NOT USE """ for docstrings.
@@ -95,7 +96,7 @@ def identify ():
 def warranty ():
        identify ()
        sys.stdout.write ('\n')
-       sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001'))
+       sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001--2002'))
        sys.stdout.write ('\n')
        sys.stdout.write ('  Han-Wen Nienhuys')
        sys.stdout.write ('  Jan Nieuwenhuizen')
@@ -110,7 +111,11 @@ def progress (s):
 
 def warning (s):
        progress (_ ("warning: ") + s)
-               
+
+def user_error (s, e=1):
+       errorport.write (program_name + ":" + _ ("error: ") + s + '\n')
+       sys.exit (e)
+       
 def error (s):
 
 
@@ -259,8 +264,6 @@ datadir = '@datadir@'
 
 
 if os.environ.has_key ('LILYPONDPREFIX') :
-# huh ? this always leads to exception.
-# or '@datadir@' == '@' + 'datadir' + '@':   
        datadir = os.environ['LILYPONDPREFIX']
 else:
        datadir = '@datadir@'
@@ -356,21 +359,23 @@ track_dependencies_p = 0
 dependency_files = []
 
 
-#
-# Try to cater for bad installations of LilyPond, that have
-# broken TeX setup.  Just hope this doesn't hurt good TeX
-# setups.  Maybe we should check if kpsewhich can find
-# feta16.{afm,mf,tex,tfm}, and only set env upon failure.
-#
+
+kpse = os.popen ('kpsexpand \$TEXMF').read()
+kpse = re.sub('[ \t\n]+$','', kpse)
+
 environment = {
-       'MFINPUTS' : datadir + '/mf' + ':',
-       'TEXINPUTS': datadir + '/tex:' + datadir + '/ps:' + '.:'
-               + os.getcwd() + ':',
-       'TFMFONTS' : datadir + '/tfm' + ':',
+       ## todo: prevent multiple addition.
+       'TEXMF' : "{%s,%s}" % (datadir, kpse) ,
        'GS_FONTPATH' : datadir + '/afm:' + datadir + '/pfa',
        'GS_LIB' : datadir + '/ps',
 }
 
+# tex needs lots of memory, more than it gets by default on Debian
+non_path_environment = {
+       'extra_mem_top' : '1000000',
+       'extra_mem_bottom' : '1000000',
+       'pool_size' : '250000',
+}
 
 def setup_environment ():
        for key in environment.keys ():
@@ -379,6 +384,10 @@ def setup_environment ():
                        val = os.environ[key] + os.pathsep + val 
                os.environ[key] = val
 
+       for key in non_path_environment.keys ():
+               val = non_path_environment[key]
+               os.environ[key] = val
+
 #what a name.
 def set_setting (dict, key, val):
        try:
@@ -414,7 +423,7 @@ def run_lilypond (files, outbase, dep_prefix):
                if dep_prefix:
                        opts = opts + ' --dep-prefix=%s' % dep_prefix
 
-       fs = '"' + string.join (files, '" "') + '"'
+       fs = string.join (files)
 
        if not verbose_p:
                # cmd = cmd + ' 1> /dev/null 2> /dev/null'
@@ -438,7 +447,7 @@ def analyse_lilypond_output (filename, extra):
 
        # search only the first 10k
        s = s[:10240]
-       for x in ('textheight', 'linewidth', 'papersize', 'orientation'):
+       for x in extra_fields:
                m = re.search (r'\\def\\lilypondpaper%s{([^}]*)}'%x, s)
                if m:
                        set_setting (extra, x, m.group (1))
@@ -613,7 +622,6 @@ None
        f.write (s)
        f.close ()
 
-       # FIXME: howto escape spaces in file names?
        cmd = 'latex \\\\nonstopmode \\\\input %s' % latex_fn
 
        if not verbose_p:
@@ -639,7 +647,7 @@ None.
        if extra['orientation'] and extra['orientation'][0] == 'landscape':
                opts = opts + ' -tlandscape'
 
-       cmd = 'dvips "%s" -o"%s" "%s"' % (opts, outbase + '.ps', outbase + '.dvi')
+       cmd = 'dvips %s -o%s %s' % (opts, outbase + '.ps', outbase + '.dvi')
        
        if not verbose_p:
                progress ( _("Running %s...") % 'dvips')
@@ -781,7 +789,7 @@ original_output = output_name
 
 
 if files and files[0] != '-':
-
+       
        # Ugh, maybe make a setup () function
        files = map (lambda x: strip_extension (x, '.ly'), files)
 
@@ -803,6 +811,10 @@ if files and files[0] != '-':
                outbase = strip_extension (outbase, i)
        files = map (abspath, files)
 
+       for i in files[:] + [output_name]:
+               if string.find (i, ' ') >= 0:
+                       user_error (_ ("filename should not contain spaces: `%s'") % i)
+                       
        if os.path.dirname (output_name) != '.':
                dep_prefix = os.path.dirname (output_name)
        else:
@@ -890,8 +902,7 @@ if files and files[0] != '-':
 else:
        # FIXME: read from stdin when files[0] = '-'
        help ()
-       errorport.write (program_name + ":" + _ ("error: ") + _ ("no files specified on command line.") + '\n')
-       sys.exit (2)
+       user_error (_ ("no files specified on command line."), 2)