6 # * Rewrite this. The control structure is too hairy.
8 # * more helpful info on lily crashes
9 # * Should use files in /tmp/ only. This potentially messes with
10 # usergenerated files in the CWD
14 =======================================================================
15 LilyPond to dvi converter
17 Features include Title information, paper size specification, and image
20 Usage: ly2dvi.py [OPTION]... [FILE]...
21 Input: LilyPond source or LilyPond generated TeX files
23 =======================================================================
27 version = '@TOPLEVEL_VERSION@'
39 # Can't grep localized msgs
40 os.environ['LC_ALL'] = ''
41 os.environ['LANG'] = ''
42 os.environ['LC_LANG'] = ''
48 This class handles all ly2dvi.py input file methods
52 __init__() Constructor
53 open(file) Open a .ly file or .tex file using lilyinclude path
54 close() Close current file
55 type() Determine file type .ly (input) or .tex (output)
56 setVars() Set title definitions found in .tex (output) file
71 open file and set private class variable __fd. The search
72 sequence is: current directory followed by the directories
73 found in include property list. Each directory is searched
74 for file, file.ly, file.sly and file.fly.
78 error: ExitNotFound Exception
81 for i in [''] + Props.get('include')[0:]:
82 ifile = os.path.join(i,file)
83 for j in ['','.ly','.fly', '.sly']:
86 this.__fd = open( jfile, 'r' )
90 sys.exit('ExitNotFound', file)
98 close file object __fd
112 Determine input file type. LilyPond source is 'input' type
113 and LilyPond generated TeX file is 'output' type
116 output: 'input' | 'output'
120 firstline = this.__fd.readline()
122 if re.match('%created by: GNU LilyPond [0-9]+[.0-9]+',firstline ):
133 Search for properties in the current input file and set the
134 appropriate values. The supported properties names are in
135 local variable varTable along with the property list
146 ( 'language', Props.setLanguage ),
147 ( 'latexheaders', Props.setHeader ),
148 ( 'paperorientation', Props.setOrientation ),
149 ( 'paperpapersize', Props.setPaperZize ),
150 ( 'papertextheight', Props.setTextHeight ),
151 ( 'paperlinewidth', Props.setLineWidth ),
152 ( 'filename', Props.setFilename ),
156 for line in this.__fd.readlines():
157 m=re.match('\\\\def\\\\lilypond([\w]+){(.*)}',line)
160 if m.group(1) == var[0]:
161 var[1](m.group(2),'file')
163 for var in Props.get('titledefs'):
164 if m.group(1) == var:
165 titles[var]=m.group(2)
167 Props.setTitles(titles,'file')
174 This class handles all ly2dvi.py output file methods
177 __lilypondDefs(opt) Send title info to output file
180 __init__() Constructor
181 write(str) Write a string to output file
182 start(file) Start the latex file
183 next() Process next output file
184 end() Finish latex file and run latex
198 def __lilypondDefs(this,opt):
200 Write titles to output
202 input: opt Supports header and subheader output
207 titles = Props.get('titles')
208 for key in titles.keys():
209 this.write('%s\\lilypond%s{%s}%%\n' % (opt,key,titles[key]))
216 Write str to current output file
218 input: str String to write
228 def start(this,file):
230 Start LaTeX file. Sets the linewidth (and possibly the
231 textheight) and leaves the page layout to the geometry
232 package. Creates temporary output filename and opens it
233 for write. Sends the LaTeX header information to output.
234 Lastly sends the title information to output.
236 input: file output file name
241 now=time.asctime(time.localtime(time.time()))
243 # Only set the textheight if it was explicitly set by the user,
244 # otherwise use the default. Helps to handle landscape correctly!
245 if Props.get('textheight') > 0:
246 textheightsetting = ',textheight=' + `Props.get('textheight')` + 'pt'
248 textheightsetting = ''
253 %% Automatically generated from %s, %s
255 \documentclass[%s]{article}
258 \usepackage{geometry}
259 \usepackage[latin1]{inputenc}
260 %%\usepackage[T1]{fontenc}
263 %% don not waste unused space at bottom of page
264 %% (unless we have footnotes ...)
267 %% Maybe this is too drastic, but let us give it a try.
268 \geometry{width=%spt%s,headheight=2mm,headsep=0pt,footskip=2mm,%s}
272 \renewcommand{\@oddhead}{\parbox{\textwidth}%%
273 {\mbox{}\small\theheader\hfill\textbf{\thepage}}}%%
275 %%\renewcommand{\@evenhead}{eve!{\small\lilypondinstrument{,}\quad\textbf{\thepage}}\hfil}%%
276 \renewcommand{\@oddfoot}{\parbox{\textwidth}{\mbox{}\thefooter}}%%
278 """ % ( program_id(), Props.get('filename'), now, Props.get('papersize'),
279 Props.get('language'), Props.get('pagenumber'), Props.get('linewidth'),
280 textheightsetting, Props.get('orientation'), Props.get('header') )
282 base, ext = os.path.splitext(file)
284 tempfile.template= base + '_ly'
285 this.__outfile = tempfile.mktemp(ext)
286 base, ext = os.path.splitext(this.__outfile)
287 this.__tmpbase = base
289 this.__fd = open(this.__outfile,"w")
291 sys.exit('ExitNoWrite', this.__outfile)
293 this.__lilypondDefs('')
303 Write LaTeX subheader information to support more than one
304 score in a document. Lastly send current title information to
315 \\def\\lilypondopus{}%
316 \\def\\lilypondpiece{}%
318 this.__lilypondDefs("\\def")
320 \\def\\theopus{\\lilypondopus}% ugh
321 \\def\\thepiece{\\lilypondpiece}%
331 Close output file and run latex on it.
335 error: ExitBadLatex Exception
338 outfile=this.__base + '.dvi'
339 if Props.get('output') != '':
340 if not os.path.exists(Props.get('output')):
341 os.mkdir(Props.get('output'))
343 outfile = os.path.join(Props.get('output'), outfile )
346 %% \vfill\hfill{\lilypondtagline}
348 \renewcommand{\@oddfoot}{\parbox{\textwidth}{\mbox{}\lilypondtagline}}%%
353 if os.path.isfile(outfile):
355 if ( os.name == 'posix' ):
356 stat = os.system('latex \'\\nonstopmode \\input %s\'' %
358 else: # Windows shells don't eat the single quotes
359 stat = os.system('latex \\nonstopmode \\input %s' %
362 sys.exit('ExitBadLatex')
363 if not os.path.isfile(outfile):
364 os.rename(this.__tmpbase + '.dvi', outfile)
366 sys.stderr.write('\n' + program_id() + ': dvi file name is %s\n\n'
369 if Props.get('postscript'):
371 if Props.get('orientation') == 'landscape':
372 dvipsopts=dvipsopts + ' -t landscape'
373 psoutfile=this.__base + '.ps'
374 if Props.get('output') != '':
375 psoutfile = os.path.join(Props.get('output'), psoutfile )
376 stat = os.system('dvips %s -o %s %s' % (dvipsopts,psoutfile,outfile))
378 sys.exit('ExitBadPostscript')
384 # ARG! THIS CODE IS BLOATED:
385 # FIXME: Junk all set/get methods.
389 This class handles all ly2dvi.py property manipulation
393 __init__() Constructor
394 set<property> methods
400 # Following is the order of priority for property assignment. The
401 # list is organized from lowest to highest priority. Each
402 # assignment is overridden by the next requester in the list.
404 # Requester Description
405 # --------- -----------
406 # init Initial default values
407 # file The values found in the LilyPond generated TeX files
408 # environment Envrionment variables LILYINCLUDE, LILYPONDPREFIX
409 # rcfile $LILYPONDPREFIX/.lilyrc
410 # rcfile $HOME/.lilyrc
412 # commandline command line arguments
414 this.__overrideTable = {
423 this.__roverrideTable = {} # reverse lookup used for debug
424 for i in this.__overrideTable.items():
425 this.__roverrideTable[i[1]]=i[0]
428 'papersize' : ['a4paper', this.__overrideTable['init']],
429 'textheight' : [0, this.__overrideTable['init']],
430 'linewidth' : [500, this.__overrideTable['init']],
431 'orientation' : ['portrait', this.__overrideTable['init']],
432 'language' : ['%', this.__overrideTable['init']],
433 'include' : [[], this.__overrideTable['init']],
434 'debug' : [0, this.__overrideTable['init']],
435 'keeplilypond' : [0, this.__overrideTable['init']],
436 'keeply2dvi' : [0, this.__overrideTable['init']],
437 'pagenumber' : ['%', this.__overrideTable['init']],
438 'separate' : [0, this.__overrideTable['init']],
439 'output' : ['', this.__overrideTable['init']],
440 'header' : ['%', this.__overrideTable['init']],
441 'dependencies' : [0, this.__overrideTable['init']],
442 'root' : ['', this.__overrideTable['init']],
443 'tmp' : ['d:\tmp', this.__overrideTable['init']],
444 'filename' : ['', this.__overrideTable['init']],
445 'titledefs' : [[], this.__overrideTable['init']],
446 'titles' : [{}, this.__overrideTable['init']],
447 'lilyOutputFiles' : [[], this.__overrideTable['init']],
448 'postscript' : [0, this.__overrideTable['init']],
452 # Try to set root and HOME first before calling rcfile
454 if os.environ.has_key('LILYPONDPREFIX'):
455 this.setRoot(os.environ['LILYPONDPREFIX'], 'environment')
457 p=os.path.split(sys.argv[0])
458 p=os.path.split(p[0])
459 # bit silly. for ly2dvi, overrules compiled-in datadir...
460 # how to do this better (without running lily, of course?
461 this.setRoot(os.path.join(p[0],'share','lilypond'), 'init')
463 if not os.environ.has_key('HOME'):
464 if os.environ.has_key('HOMEDRIVE') and \
465 os.environ.has_key('HOMEPATH'):
466 os.environ['HOME'] = os.environ['HOMEDRIVE'] + \
467 os.environ['HOMEPATH']
469 os.environ['HOME'] = os.curdir
471 this.rcfile() # Read initialization file(s)
473 if os.environ.has_key('LILYINCLUDE'):
474 tmp=this.get('include')
475 for s in string.split(os.environ['LILYINCLUDE'],os.pathsep):
477 this.__set('include', tmp, 'environment')
481 if os.environ.has_key ('TEXINPUTS'):
482 t = os.environ['TEXINPUTS'] + os.pathsep
483 os.environ['TEXINPUTS'] = t + \
484 os.path.join(this.get('root'), 'tex' ) + \
485 os.pathsep + os.path.join(this.get('root'), 'ps' )
488 if os.environ.has_key ('MFINPUTS'):
489 t = os.environ['MFINPUTS']
490 os.environ['MFINPUTS'] = t + os.pathsep + \
491 os.path.join(this.get('root'), 'mf')
493 if os.environ.has_key('TMP'):
494 this.__set('tmp',os.environ['TMP'],'environment')
497 def read_titledefs (this):
498 fd=this.get_texfile_path ('titledefs.tex')
501 for line in fd.readlines():
502 m=re.match('\\\\newcommand\*{\\\\lilypond([\w]+)}',line)
504 mudefs.append(m.group(1))
506 this.__set('titledefs', mudefs, 'init')
511 def __set(this,var,value,requester):
513 All of the set methods call this to set a property. If the value
514 was last set by a requestor of lesser priority the new value is
515 assigned, else the old value has priority and is unchanged.
518 if this.__overrideTable[requester] < this.__data[var][1]:
521 this.__data[var] = [value, this.__overrideTable[requester]]
528 All of the get methods call this to get a property value. List
529 variable types are return by value to facilitate an append operation.
532 if var == 'include' or var == 'lilyOutputFiles':
533 return this.__data[var][0][0:] # return a copy not a ref
535 return this.__data[var][0]
540 def get_texfile_path (this, var):
542 locate and open titledefs.tex file
546 path = os.path.join(this.get('root'), 'tex', var)
549 cmd =('kpsewhich tex %s %s' % (var,errorlog))
550 pipe = os.popen (cmd, 'r')
551 path = pipe.readline ()[:-1] # chop off \n
552 return_status = pipe.close()
553 if return_status and not path:
554 path = os.path.join(this.get('root'), 'tex', var)
564 Read initialization file(s)
569 ( 'DEBUG', this.setDebug ),
570 ( 'DEPENDENCIES', this.setDependencies ),
571 ( 'KEEPLILYPOND', this.setKeeplilypond ),
572 ( 'KEEPLY2DVI', this.setKeeply2dvi ),
573 ( 'LANGUAGE', this.setLanguage ),
574 ( 'LATEXHF', this.setHeader ),
575 ( 'LILYINCLUDE', this.setInclude ),
576 ( 'LILYPONDPREFIX', this.setRoot ),
577 ( 'NONUMBER', this.setNonumber ),
578 ( 'ORIENTATION', this.setOrientation ),
579 ( 'OUTPUTDIR', this.setOutput ),
580 ( 'PAPERSIZE', this.setPaperZize ),
581 ( 'PHEIGHT', this.setTextHeight ),
582 ( 'POSTSCRIPT', this.setPostscript ),
583 ( 'PWIDTH', this.setLineWidth ),
584 ( 'SEPARATE', this.setSeparate ),
585 ( 'TMP', this.setTmp ),
588 if ( os.name == 'posix' ):
589 dotFilename='.lilyrc'
590 else: # Windows apps like edit choke on .lilyrc
591 dotFilename='_lilyrc'
593 for d in [os.path.join(this.get('root'),'ly'), \
594 os.environ['HOME'], os.curdir ]:
595 file=os.path.join(d,dotFilename)
597 fd = open( file, 'r' )
601 for line in fd.readlines():
602 if re.match('#.*',line):
604 m=re.search('([\w]+)=(.*)',line)
607 if m.group(1) == var[0]:
608 var[1](m.group(2),'rcfile')
615 def setPaperZize(this,size,requester):
617 Set paper size properties
621 # regex width height name
622 # ----- ----- ------ ----
623 ( 'a0.*', 2389, 3381, 'a0paper' ),
624 ( 'a1$|a1p.*', 1690, 2389, 'a1paper' ),
625 ( 'a2.*', 1194, 1690, 'a2paper' ),
626 ( 'a3.*', 845, 1194, 'a3paper' ),
627 ( 'a4.*', 597, 845, 'a4paper' ),
628 ( 'a5.*', 423, 597, 'a5paper' ),
629 ( 'a6.*', 298, 423, 'a6paper' ),
630 ( 'a7.*', 211, 298, 'a7paper' ),
631 ( 'a8.*', 305, 211, 'a8paper' ),
632 ( 'a9.*', 105, 305, 'a9paper' ),
633 ( 'a10.*', 74, 105, 'a10paper' ),
634 ( 'b0.*', 2847, 4023, 'b0paper' ),
635 ( 'b1.*', 2012, 2847, 'b1paper' ),
636 ( 'b2.*', 1423, 2012, 'b2paper' ),
637 ( 'b3.*', 1006, 1423, 'b3paper' ),
638 ( 'b4.*', 712, 1006, 'b4paper' ),
639 ( 'b5.*', 503, 712, 'b5paper' ),
640 ( 'archA$', 650, 867, 'archApaper' ),
641 ( 'archB$', 867, 1301, 'archBpaper' ),
642 ( 'archC$', 1301, 1734, 'archCpaper' ),
643 ( 'archD$', 1734, 2602, 'archDpaper' ),
644 ( 'archE$', 2602, 3469, 'archEpaper' ),
645 ( 'flsa$|flse$', 614, 940, 'flsapaper' ),
646 ( 'halfletter$', 397, 614, 'halfletterpaper' ),
647 ( 'ledger$', 1229, 795, 'ledgerpaper' ),
648 ( 'legal$', 614, 1012, 'legalpaper' ),
649 ( 'letter$', 614, 795, 'letterpaper' ),
650 ( 'note$', 542, 723, 'notepaper' )
654 for paper in paperTable:
655 if re.match(paper[0],size):
657 this.__set('papersize',paper[3],requester)
661 sys.exit('ExitBadPaper',size)
666 def setTextHeight(this,size,requester):
668 Set textheight property
671 m=re.match('([0-9][.0-9]*)(cm|mm|pt|$)',size)
673 if m.group(2) == 'cm':
674 this.__set('textheight',\
675 float(m.group(1)) * 72.27/2.54, requester )
676 elif m.group(2) == 'mm':
677 this.__set('textheight',\
678 float(m.group(1)) * 72.27/25.4, requester )
679 elif m.group(2) == 'pt':
680 this.__set('textheight', float(m.group(1)), requester )
681 elif m.group(2) == '':
682 this.__set('textheight', float(m.group(1)), requester )
684 sys.exit('ExitBadHeight', m.group(2))
686 sys.exit('ExitBadHeight', size)
691 def setLineWidth(this,size,requester):
693 Set linewidth propery
696 m=re.match('([0-9][.0-9]*)(cm|mm|pt|$)',size)
698 if m.group(2) == 'cm':
699 this.__set('linewidth', \
700 float(m.group(1)) * 72.27/2.54, requester )
701 elif m.group(2) == 'mm':
702 this.__set('linewidth', \
703 float(m.group(1)) * 72.27/25.4, requester )
704 elif m.group(2) == 'pt':
705 this.__set('linewidth', float(m.group(1)), requester )
706 elif m.group(2) == '':
707 this.__set('linewidth', float(m.group(1)), requester )
709 sys.exit('ExitBadWidth', m.group(2))
711 sys.stderr.write ('ly2dvi: warning: ignoring linewidth: ' + size + '\n')
716 def setOrientation(this,orient,requester):
718 Set orientation property
721 if orient == 'landscape' or orient == 'portrait':
722 this.__set('orientation', orient, requester )
724 sys.exit('ExitBadOrient', orient)
729 def setLanguage(this,lang,requester):
731 Set language property
734 this.__set('language', '\\usepackage[%s]{babel}' % (lang), requester )
739 def setInclude(this,inc, requester):
741 Append an include path
744 tmp = this.get('include')
746 this.__set('include', tmp, requester )
751 def setDebug(this,value,requester):
753 Set or Clear debug flag
757 this.__set('debug',1,requester)
759 this.__set('debug',0,requester)
764 def setKeeplilypond(this, value, requester):
766 Set or Clear keeplilypond flag
770 this.__set('keeplilypond',1,requester)
772 this.__set('keeplilypond',0,requester)
777 def setKeeply2dvi(this, value, requester):
779 Set or Clear keeply2dvi flag
783 this.__set('keeply2dvi',1,requester)
785 this.__set('keeply2dvi',0,requester)
790 def setNonumber(this, value, requester):
796 this.__set('pagenumber','\\pagestyle{empty}',requester)
798 this.__set('pagenumber','%',requester)
803 def setSeparate(this, value, requester):
805 Set or Clear separate flag
809 this.__set('separate',1,requester)
811 this.__set('separate',0,requester)
814 # Set output directory name
816 def setOutput(this,out,requester):
817 this.__set('output',out,requester)
820 # Set latex header name
822 def setHeader(this,head, requester):
823 this.__set('header','\\input{' + head + '}',requester)
826 # Set or Clear Dependencies flag to generate makefile dependencies
828 def setDependencies(this, value, requester):
830 Set or Clear dependencies flag
834 this.__set('dependencies',1,requester)
836 this.__set('dependencies',0,requester)
841 def setTmp(this,dir, requester):
842 this.__set('tmp',dir,requester)
845 # Set lilypond source file name
847 def setFilename(this,file, requester):
848 this.__set('filename',file,requester)
853 def setTitles(this,titles, requester):
854 this.__set('titles',titles,requester)
859 def addLilyOutputFiles(this,filelist,requester):
861 Add a to the lily output list
864 tmp = this.get('lilyOutputFiles')
866 this.__set('lilyOutputFiles',tmp,requester)
869 # Set/Clear postscript flag
871 def setPostscript(this,value,requester):
877 this.__set('postscript',1,requester)
879 this.__set('postscript',0,requester)
884 def setRoot(this,path, requester):
886 Set LilyPond root directory
889 os.environ['LILYPONDPREFIX'] = path
890 if os.name == 'nt' or os.name == 'dos':
891 path = unc2dos(path);
893 this.__set('root',path,requester)
899 def printProps(this):
904 for key in this.__data.keys():
905 print "%s <%s>:<%s>" % (key,this.get(key),
906 this.__roverrideTable[this.__data[key][1]])
916 if len(Props.get('include')) > 0:
917 inc = string.join (map (lambda x: '-I "%s"' % x, Props.get('include')))
920 if Props.get('dependencies'):
927 def writeLilylog(file,contents):
928 if Props.get('keeplilypond'):
929 base, ext = os.path.splitext(file)
930 tempfile.template=base + "_li"
931 file=tempfile.mktemp('.log')
932 output = Props.get('output')
934 file = os.path.join( output, file )
936 fd = open( file, 'w' )
938 sys.exit('ExitNoWrite', file)
942 def getTeXFile(contents):
944 for line in string.split(contents,'\n'):
945 m = re.search('paper output to (.+)\.\.\.', line)
947 texfiles.append(m.group(1))
950 sys.exit('ExitNoTeXName')
956 Convert a path of format //<drive>/this/that/the/other to
957 <drive>:\this\that\the\other
959 m=re.match('^//([A-Za-z])(/.*)$',path)
961 return m.group(1) + ':' + os.path.normpath(m.group(2))
966 return 'ly2dvi (GNU LilyPond) ' + version;
971 return os.environ['MAILADDRESS']
973 return '(address unknown)'
977 sys.stderr.write (program_id () + '\n')
979 def print_version ():
980 sys.stdout.write (program_id () + '\n')
984 """Usage: %s [OPTION]... [FILE]...
986 Generate dvi file from LilyPond source/output
989 -D,--debug increase verbosity
990 -F,--headers= name of additional LaTeX headers file
991 -H,--Height= set paper height (points) (see manual page)
992 -I,--include=DIR add DIR to LilyPond\'s search path
993 -K,--keeplilypond keep LilyPond output files
994 -L,--landscape set landscape orientation
995 -N,--nonumber switch off page numbering
996 -O,--orientation= set orientation (obsolete -- use -L instead)
997 -P,--postscript generate PostScript file
998 -W,--Width= set paper width (points) (see manual page)
999 -M,--dependencies tell LilyPond to make a dependencies file
1000 -h,--help this help text
1001 -k,--keeply2dvi keep ly2dvi output files
1002 -l,--language= give LaTeX language (babel)
1003 -o,--output= set output directory
1004 -p,--papersize= give LaTeX papersize (eg. a4)
1005 -s,--separate run all files separately through LaTeX
1007 files may be (a mix of) input to or output from LilyPond(1)
1017 """Generate dvi files from LilyPond source/output"""
1020 outfile = TeXOutput()
1024 (options, files) = getopt.getopt (sys.argv[1:],
1025 'DF:H:I:KLNPW:Mhkl:o:p:s',
1026 ['debug', 'headers=', 'Height=',
1027 'include=', 'keeplilypond', 'landscape',
1028 'nonumber', 'Width=', 'dependencies',
1029 'help', 'keeply2dvi', 'language=',
1030 'output=', 'version', 'papersize=', 'separate',
1036 if o == '--debug' or o == '-D':
1037 Props.setDebug(1,'commandline')
1038 elif o == '--headers' or o == '-F':
1039 Props.setHeader(a,'commandline')
1040 elif o == '--include' or o == '-I':
1041 Props.setInclude(a,'commandline')
1042 elif o == '--Height' or o == '-H':
1043 Props.setTextHeight(a,'commandline')
1044 elif o == '--keeplilypond' or o == '-K':
1045 Props.setKeeplilypond(1,'commandline')
1046 elif o == '--landscape' or o == '-L':
1047 Props.setOrientation('landscape','commandline')
1048 elif o == '--nonumber' or o == '-N':
1049 Props.setNonumber(1,'commandline')
1050 elif o == '--Width' or o == '-W':
1051 Props.setLineWidth(a,'commandline')
1052 elif o == '--dependencies' or o == '-M':
1053 Props.setDependencies(1,'commandline')
1054 elif o == '--help' or o == '-h':
1057 elif o == '--keeply2dvi' or o == '-k':
1058 Props.setKeeply2dvi(1,'commandline')
1059 elif o == '--language' or o == '-l':
1060 Props.setLanguage(a,'commandline')
1061 elif o == '--output' or o == '-o':
1062 Props.setOutput(a,'commandline')
1063 elif o == '--papersize' or o == '-p':
1064 Props.setPaperZize(a,'commandline')
1065 elif o == '--separate' or o == '-s':
1066 Props.setSeparate(1,'commandline')
1067 elif o == '--postscript' or o == '-P':
1068 Props.setPostscript(1,'commandline')
1069 elif o == '--version':
1077 Props.read_titledefs ()
1082 type = infile.type()
1084 if type == 'source':
1085 if os.environ.has_key('OS') and \
1086 os.environ['OS'] == 'Windows_95':
1087 cmd = 'ash -c "lilypond %s %s 2>&1"' %(getLilyopts(), file)
1089 cmd = 'lilypond %s %s 2>&1' % (getLilyopts(), file)
1090 sys.stderr.write ('executing: %s\n'% cmd)
1092 fd = os.popen(cmd , 'r')
1097 sys.stderr.write (s)
1104 sys.stderr.write (s)
1110 sys.exit('ExitBadLily', cmd )
1111 texFiles=getTeXFile(log)
1112 writeLilylog(file,log)
1113 Props.addLilyOutputFiles(texFiles,'program')
1114 texInputFiles = texInputFiles + texFiles
1116 texInputFiles.append(file)
1119 for file in texInputFiles:
1121 infile.setVars() # first pass set variables
1123 if Props.get('debug'):
1126 outfile.start(file) # allow for specified name
1132 if Props.get('separate'):
1136 if not Props.get('separate'):
1140 sys.exit('ExitBadArgs','No files specified')
1146 'ExitInterupt' : ['Ouch!', 1 ],
1147 'ExitBadArgs' : ['Wrong number of arguments', 2 ],
1148 'ExitNotFound' : ['File not found', 3 ],
1149 'ExitBadPaper' : ['Unknown papersize', 4 ],
1150 'ExitBadHeight' : ['Invalid Height specification', 5 ],
1151 'ExitBadWidth' : ['Invalid Width specification', 6 ],
1152 'ExitBadOrient' : ['Invalid Orientation specification', 7 ],
1153 'ExitNoWrite' : ['Permission denied', 8 ],
1154 'ExitNoTeXName' : ['Hmm, I could not find an output file name', 9 ],
1155 'ExitBadLily' : ['LilyPond failed', 10 ],
1156 'ExitBadLatex' : ['Latex failed', 11 ],
1157 'ExitBadPostscript' : ['Postscript failed', 12 ],
1158 'ExitUnknown' : ['Unknown Exit Code', 20 ],
1164 if not Props.get('keeplilypond'):
1165 lilyfiles = Props.get('lilyOutputFiles')
1166 if not Props.get('keeply2dvi'):
1167 tmpfiles = glob.glob('*_ly[0-9]*.*')
1168 for file in lilyfiles + tmpfiles:
1169 if os.path.isfile(file):
1173 Props = Properties()
1178 except KeyboardInterrupt:
1179 print ExitTable['ExitInterupt'][0]
1181 sys.exit(ExitTable['ExitInterupt'][1])
1183 except SystemExit, errno:
1184 if ExitTable.has_key(errno.args[0]):
1185 msg = ExitTable[errno.args[0]]
1187 msg = ExitTable['ExitUnknown']
1188 if len(errno.args) > 1:
1189 sys.stderr.write( '%s: %s: %s\n' % (name, msg[0], errno.args[1]))
1191 sys.stderr.write( '%s %s\n' % (name, msg[0]))
1192 if Props.get('debug'):