#!@PYTHON@
+
# Run lilypond, latex, dvips.
#
# This is the third incarnation of ly2dvi.
# 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.
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')
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):
if os.environ.has_key ('LILYPONDPREFIX') :
-# huh ? this always leads to exception.
-# or '@datadir@' == '@' + 'datadir' + '@':
datadir = os.environ['LILYPONDPREFIX']
else:
datadir = '@datadir@'
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 ():
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:
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'
# 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))
f.write (s)
f.close ()
- # FIXME: howto escape spaces in file names?
cmd = 'latex \\\\nonstopmode \\\\input %s' % latex_fn
if not verbose_p:
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')
if files and files[0] != '-':
-
+
# Ugh, maybe make a setup () function
files = map (lambda x: strip_extension (x, '.ly'), files)
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:
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)