#!@PYTHON@
+
+# TODO:
+#
+# * Rewrite this. The control structure is too hairy.
+# * (c) on page 1
+# * more helpful info on lily crashes
+# * Should use files in /tmp/ only. This potentially messes with
+# usergenerated files in the CWD
+
+
"""
=======================================================================
LilyPond to dvi converter
"""
name = 'ly2dvi'
-version = '0.0.13'
+version = '@TOPLEVEL_VERSION@'
errorlog = ''
import sys
import glob
import tempfile
+os.environ['LANG'] = '' # Can't grep localized msgs
+
+
class Input:
"""
This class handles all ly2dvi.py input file methods
-
+
Public methods:
__init__() Constructor
pageheight = Props.get('pageheight')
pagewidth = Props.get('pagewidth')
- horizontalMarginArg = ( (pagewidth - linewidth)/2 )
- verticalMarginArg = ( (pageheight - textheight)/2 )
- top="""\
+ top= r"""
%% Creator: %s
%% Automatically generated from %s, %s
-\\documentclass[%s]{article}
+\documentclass[%s]{article}
%s
-\\usepackage{geometry}
-\\usepackage[latin1]{inputenc}
-%%\\usepackage[T1]{fontenc}
+\usepackage{geometry}
+\usepackage[latin1]{inputenc}
+%%\usepackage[T1]{fontenc}
+%%
%s
-%%\\addtolength{\\oddsidemargin}{-1cm}
-%%\\addtolength{\\topmargin}{-1cm}
-%%\\setlength{\\textwidth}{%s}
-%%\\setlength{\\textheight}{%s}
-\\geometry{width=%spt, left=%spt, height=%spt, top=%spt}
-\\input lilyponddefs
-\\input titledefs
-%s
-\\begin{document}
+%% don not waste unused space at bottom of page
+%% (unless we have footnotes ...)
+%%\headheight9pt
+%%\headsep0pt
+%% Maybe this is too drastic, but let us give it a try.
+\geometry{width=%spt, textheight=%spt,headheight=2mm,headsep=0pt,footskip=2mm}
+\input{titledefs}
+%s
+\makeatletter
+\renewcommand{\@oddhead}{\parbox{\textwidth}%%
+ {\mbox{}\small\theheader\hfill\textbf{\thepage}}}%%
+%% UGR.
+%%\renewcommand{\@evenhead}{eve!{\small\mudelainstrument{,}\quad\textbf{\thepage}}\hfil}%%
+\renewcommand{\@oddfoot}{\parbox{\textwidth}{\mbox{}\thefooter}}%%
+\begin{document}
""" % ( program_id(), Props.get('filename'), now, Props.get('papersize'),
- Props.get('language'), Props.get('pagenumber'), linewidth, textheight,
- linewidth, horizontalMarginArg, textheight, verticalMarginArg,
- Props.get('header') )
+ Props.get('language'), Props.get('pagenumber'), linewidth,
+ textheight, Props.get('header') )
base, ext = os.path.splitext(file)
this.__base = base
if Props.get('output') != '':
outfile = os.path.join(Props.get('output'), outfile )
- this.write("""\
-\\vfill\\hfill{\\mudelatagline}
-\\end{document}
+ this.write(r"""
+%% \vfill\hfill{\mudelatagline}
+\makeatletter
+\renewcommand{\@oddfoot}{\parbox{\textwidth}{\mbox{}\mudelatagline}}%%
+\makeatother
+\end{document}
""")
this.__fd.close()
if os.path.isfile(outfile):
# Requester Description
# --------- -----------
# init Initial default values
- # file The values found in the lilypond generated TeX files
+ # file The values found in the LilyPond generated TeX files
# environment Envrionment variables LILYINCLUDE, LILYPONDPREFIX
# rcfile $LILYPONDPREFIX/.lilyrc
# rcfile $HOME/.lilyrc
t=''
if os.environ.has_key ('MFINPUTS'):
t = os.environ['MFINPUTS']
- os.environ['MFINPUTS'] = os.pathsep + t + \
+ os.environ['MFINPUTS'] = t + os.pathsep + \
os.path.join(this.get('root'), 'mf')
if os.environ.has_key('TMP'):
this.__set('tmp',os.environ['TMP'],'environment')
-
+
+ def read_titledefs (this):
fd=this.get_texfile_path ('titledefs.tex')
mudefs=[]
# Set latex header name
#
def setHeader(this,head, requester):
- this.__set('header',head,requester)
+ this.__set('header','\\input{' + head + '}',requester)
#
# Set or Clear Dependencies flag to generate makefile dependencies
#
def setRoot(this,path, requester):
"""
- Set lilypond root directory
+ Set LilyPond root directory
"""
os.environ['LILYPONDPREFIX'] = path
def getTeXFile(contents):
texfiles=[]
for line in string.split(contents,'\n'):
- m = re.search('^Paper output to (.+)\.\.\.', line)
+ m = re.search('paper output to (.+)\.\.\.', line)
if m:
texfiles.append(m.group(1))
def program_id ():
- return name + ' ' + version;
+ return 'ly2dvi (GNU LilyPond) ' + version;
def mailaddress():
def identify ():
sys.stderr.write (program_id () + '\n')
+def print_version ():
+ sys.stdout.write (program_id () + '\n')
+
def help ():
- sys.stderr.write (
- 'Generate dvi file from mudela or lilypond output\n'
- 'Usage: ' + name + ' [OPTION]... [FILE]...\n'
- '\n'
- 'Options:\n'
- ' -D,--debug increase verbosity\n'
- ' -F,--headers= name of additional LaTeX headers file\n'
- ' -H,--Height= set paper height (points) (see manual page)\n'
- ' -I,--include=DIR add DIR to LilyPond\'s search path\n'
- ' -K,--keeplilypond keep lilypond output files\n'
- ' -L,--landscape set landscape orientation\n'
- ' -N,--nonumber switch off page numbering\n'
- ' -O,--orientation= set orientation (obsolete - use -L instead)\n'
- ' -P,--postscript generate postscript file\n'
- ' -W,--Width= set paper width (points) (see manual page)\n'
- ' -M,--dependencies tell lilypond make a dependencies file\n'
- ' -h,--help this help text\n'
- ' -k,--keeply2dvi keep ly2dvi output files\n'
- ' -l,--language= give LaTeX language (babel)\n'
- ' -o,--output= set output directory\n'
- ' -p,--papersize= give LaTeX papersize (eg. a4)\n'
- ' -s,--separate run all files separately through LaTeX\n'
- '\n'
- 'files may be (a mix of) input to or output from lilypond(1)\n'
- )
+ sys.stdout.write (
+"""Usage: %s [OPTION]... [FILE]...
+
+Generate dvi file from LilyPond source/output
+
+Options:
+ -D,--debug increase verbosity
+ -F,--headers= name of additional LaTeX headers file
+ -H,--Height= set paper height (points) (see manual page)
+ -I,--include=DIR add DIR to LilyPond\'s search path
+ -K,--keeplilypond keep LilyPond output files
+ -L,--landscape set landscape orientation
+ -N,--nonumber switch off page numbering
+ -O,--orientation= set orientation (obsolete -- use -L instead)
+ -P,--postscript generate PostScript file
+ -W,--Width= set paper width (points) (see manual page)
+ -M,--dependencies tell LilyPond to make a dependencies file
+ -h,--help this help text
+ -k,--keeply2dvi keep ly2dvi output files
+ -l,--language= give LaTeX language (babel)
+ -o,--output= set output directory
+ -p,--papersize= give LaTeX papersize (eg. a4)
+ -s,--separate run all files separately through LaTeX
+
+files may be (a mix of) input to or output from LilyPond(1)
+""" % name)
\f
#
def main():
- """Generate dvi files from lilypond source/output"""
+ """Generate dvi files from LilyPond source/output"""
infile = Input()
outfile = TeXOutput()
'include=', 'keeplilypond', 'landscape',
'nonumber', 'Width=', 'dependencies',
'help', 'keeply2dvi', 'language=',
- 'output=', 'papersize=', 'separate',
+ 'output=', 'version', 'papersize=', 'separate',
'postscript'])
+
for opt in options:
o = opt[0]
a = opt[1]
Props.setDependencies(1,'commandline')
elif o == '--help' or o == '-h':
help()
- return 0
+ sys.exit (0)
elif o == '--keeply2dvi' or o == '-k':
Props.setKeeply2dvi(1,'commandline')
elif o == '--language' or o == '-l':
Props.setSeparate(1,'commandline')
elif o == '--postscript' or o == '-P':
Props.setPostscript(1,'commandline')
-
+ elif o == '--version':
+ print_version ()
+ return 0
+ else:
+ print o
+ raise getopt.error
+
+ identify()
+ Props.read_titledefs ()
+
if len(files):
for file in files:
infile.open(file)
'ExitBadWidth' : ['Invalid Width specification', 6 ],
'ExitBadOrient' : ['Invalid Orientation specification', 7 ],
'ExitNoWrite' : ['Permission denied', 8 ],
- 'ExitNoTeXName' : ['hmm, I could not find an output file name', 9 ],
- 'ExitBadLily' : ['Lilypond failed', 10 ],
+ 'ExitNoTeXName' : ['Hmm, I could not find an output file name', 9 ],
+ 'ExitBadLily' : ['LilyPond failed', 10 ],
'ExitBadLatex' : ['Latex failed', 11 ],
'ExitBadPostscript' : ['Postscript failed', 12 ],
'ExitUnknown' : ['Unknown Exit Code', 20 ],
os.remove(file)
-identify()
Props = Properties()
try: