"""
name = 'ly2dvi'
-version = '0.0.12'
+version = '@TOPLEVEL_VERSION@'
errorlog = ''
import sys
import string
import time
import glob
+import tempfile
class Input:
"""
This class handles all ly2dvi.py input file methods
-
+
Public methods:
__init__() Constructor
linewidth, horizontalMarginArg, textheight, verticalMarginArg,
Props.get('header') )
- pathcomp = os.path.splitext(file)
- this.__base = pathcomp[0]
- this.__outfile = '%s.%d%s' % (pathcomp[0], os.getpid(), pathcomp[1])
+ base, ext = os.path.splitext(file)
+ this.__base = base
+ tempfile.template= base + '_ly'
+ this.__outfile = tempfile.mktemp(ext)
+ base, ext = os.path.splitext(this.__outfile)
+ this.__tmpbase = base
try:
this.__fd = open(this.__outfile,"w")
except:
this.write(top)
this.__mudelaDefs('')
this.write("""\
-\\cmrtwenty% ugh
\\makelilytitle
""")
\\end{document}
""")
this.__fd.close()
+ if os.path.isfile(outfile):
+ os.remove(outfile)
if ( os.name == 'posix' ):
stat = os.system('latex \'\\nonstopmode \\input %s\'' %
(this.__outfile))
(this.__outfile))
if stat:
sys.exit('ExitBadLatex')
- if os.path.isfile(outfile):
- os.remove(outfile)
- os.rename(this.__base + '.' + str(os.getpid()) + '.dvi', outfile)
- sys.stderr.write( '\n' + program_id() + ': dvi file name is %s\n\n'
- % (outfile))
+ if not os.path.isfile(outfile):
+ os.rename(this.__tmpbase + '.dvi', outfile)
+
+ sys.stderr.write('\n' + program_id() + ': dvi file name is %s\n\n'
+ % (outfile))
if Props.get('postscript'):
psoutfile=this.__base + '.ps'
\f
+
+# ARG! THIS CODE IS BLOATED:
+# FIXME: Junk all set/get methods.
+
class Properties:
"""
This class handles all ly2dvi.py property manipulation
#
# Set or Clear Dependencies flag to generate makefile dependencies
#
- def setDependencies(this, requester):
+ def setDependencies(this, value, requester):
"""
Set or Clear dependencies flag
"""
else:
if Props.get('dependencies'):
- dep=' -d'
+ dep=' -M'
else:
dep=''
return inc + dep
return inc
-def writeLilylog(contents):
+def writeLilylog(file,contents):
if Props.get('keeplilypond'):
- file='lilylog.' + str(os.getpid())
+ base, ext = os.path.splitext(file)
+ tempfile.template=base + "_li"
+ file=tempfile.mktemp('.log')
output = Props.get('output')
if output != '':
file = os.path.join( output, file )
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 ())
+
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'
- ' -d,--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 mudela or lilypond 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 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
infile = Input()
outfile = TeXOutput()
texInputFiles=[]
+ tempfile.tempdir=""
(options, files) = getopt.getopt (sys.argv[1:],
- 'DF:H:I:KLNPW:dhkl:o:p:s',
+ 'DF:H:I:KLNPW:Mhkl:o:p:s',
['debug', 'headers=', 'Height=',
'include=', 'keeplilypond', 'landscape',
'nonumber', 'Width=', 'dependencies',
'help', 'keeply2dvi', 'language=',
- 'output=', 'papersize=', 'separate',
+ 'output=', 'version', 'papersize=', 'separate',
'postscript'])
for opt in options:
o = opt[0]
Props.setNonumber(1,'commandline')
elif o == '--Width' or o == '-W':
Props.setLineWidth(a,'commandline')
- elif o == '--dependencies' or o == '-d':
+ elif o == '--dependencies' or o == '-M':
Props.setDependencies(1,'commandline')
elif o == '--help' or o == '-h':
help()
- return 0
+ return 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
+
+ identify()
+
if len(files):
for file in files:
infile.open(file)
if stat:
sys.exit('ExitBadLily', cmd )
texFiles=getTeXFile(log)
- writeLilylog(log)
+ writeLilylog(file,log)
Props.addLilyOutputFiles(texFiles,'program')
texInputFiles = texInputFiles + texFiles
else:
if Props.get('debug'):
Props.printProps()
if firstfile:
- outfile.start(file)
+ outfile.start(file) # allow for specified name
else:
outfile.next()
outfile.write("""\
if not Props.get('keeplilypond'):
lilyfiles = Props.get('lilyOutputFiles')
if not Props.get('keeply2dvi'):
- tmpfiles = glob.glob('*.' + str(os.getpid()) + '.*' )
+ tmpfiles = glob.glob('*_ly[0-9]*.*')
for file in lilyfiles + tmpfiles:
if os.path.isfile(file):
os.remove(file)
-identify()
Props = Properties()
try: