]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/ly2dvi.py
release: 1.1.45
[lilypond.git] / scripts / ly2dvi.py
index 287fa5ad219f37911da7dc2b46e9bd9d72fb4b33..e3b42ffa8ea1934ca98a6d39d0830d3426479715 100644 (file)
@@ -14,7 +14,7 @@ Output: DVI file
 """
 
 name = 'ly2dvi'
-version = '0.0.6'
+version = '0.0.11'
 errorlog = ''
 
 import sys
@@ -54,7 +54,7 @@ class Input:
         open file and set private class variable __fd.  The search
         sequence is: current directory followed by the directories
         found in include property list.  Each directory is searched
-        for file, file.ly, and file.fly.
+        for file, file.ly, file.sly and file.fly.
         
         input:  file   filename
         output: void
@@ -63,7 +63,7 @@ class Input:
 
         for i in [''] + Props.get('include')[0:]:
             ifile = os.path.join(i,file)
-            for j in ['','.ly','.fly']:
+            for j in ['','.ly','.fly', '.sly']:
                 jfile = ifile+j
                 try:
                     this.__fd = open( jfile, 'r' )
@@ -102,7 +102,7 @@ class Input:
 
         firstline = this.__fd.readline()
         this.__fd.seek(0)
-        if  re.match('% Creator: GNU LilyPond [0-9]+[.0-9]+',firstline ):
+        if  re.match('%created by: GNU LilyPond [0-9]+[.0-9]+',firstline ):
             return 'output'
         else:
             return 'source'
@@ -231,7 +231,7 @@ class TeXOutput:
         else:
             pageheight = Props.get('pageheight')
             pagewidth = Props.get('pagewidth')
-                             
+                                
         horizontalMarginArg =  ( (pagewidth - linewidth)/2 )   
         verticalMarginArg =  ( (pageheight - textheight)/2  )
 
@@ -319,7 +319,7 @@ class TeXOutput:
             outfile = os.path.join(Props.get('output'), outfile )
             
         this.write("""\
-\\vfill\\hfill{\\LilyIdString}
+\\vfill\\hfill{\\mudelatagline}
 \\end{document}
 """)
         this.__fd.close()
@@ -341,7 +341,7 @@ class TeXOutput:
             psoutfile=this.__base + '.ps'
             if Props.get('output') != '':
                 psoutfile = os.path.join(Props.get('output'), psoutfile )
-            stat = os.system('dvips -o %s %s 2>&1' % (psoutfile,outfile))
+            stat = os.system('dvips -o %s %s' % (psoutfile,outfile))
             if stat:
                 sys.exit('ExitBadPostscript')
             
@@ -370,7 +370,7 @@ class Properties:
         # init          Initial default values
         # file          The values found in the lilypond generated TeX files
         # environment   Envrionment variables LILYINCLUDE, LILYPONDPREFIX
-        # rcfile        $LILYPONDPREFIX/share/lilypond/.lilyrc
+        # rcfile        $LILYPONDPREFIX/.lilyrc
         # rcfile        $HOME/.lilyrc
         # rcfile        ./.lilyrc
         # commandline   command line arguments
@@ -393,7 +393,7 @@ class Properties:
             'pageheight'   :  [845, this.__overrideTable['init']],
             'papersize'    :  ['a4paper', this.__overrideTable['init']],
             'textheight'   :  [0, this.__overrideTable['init']],
-            'linewidth'    :  [0, this.__overrideTable['init']],
+            'linewidth'    :  [500, this.__overrideTable['init']],
             'orientation'  :  ['portrait', this.__overrideTable['init']],
             'language'     :  ['%', this.__overrideTable['init']],
             'include'      :  [[], this.__overrideTable['init']],
@@ -422,7 +422,9 @@ class Properties:
         else:
             p=os.path.split(sys.argv[0])
             p=os.path.split(p[0])
-            this.setRoot(p[0],'init')
+           # bit silly. for ly2dvi, overrules compiled-in datadir...
+           # how to do this better (without running lily, of course?
+            this.setRoot(os.path.join(p[0],'share','lilypond'), 'init')
 
         if not os.environ.has_key('HOME'):
             if os.environ.has_key('HOMEDRIVE') and \
@@ -441,17 +443,18 @@ class Properties:
             this.__set('include', tmp, 'environment')    
 
 
-        t=''
+        t= os.pathsep
        if os.environ.has_key ('TEXINPUTS'):
-               t = os.pathsep + os.environ['TEXINPUTS']
-        os.environ['TEXINPUTS'] = os.path.join(this.get('root'), 'share',
-                                              'lilypond', 'tex' ) + t
+               t = os.environ['TEXINPUTS'] + os.pathsep
+        os.environ['TEXINPUTS'] = t + \
+       os.path.join(this.get('root'), 'tex' ) + \
+       os.pathsep + os.path.join(this.get('root'), 'ps' )
 
         t=''
        if os.environ.has_key ('MFINPUTS'):
-               t = os.pathsep + os.environ['MFINPUTS']
-        os.environ['MFINPUTS'] = os.path.join(this.get('root'), 'share',
-                                              'lilypond', 'mf' ) + t
+               t = os.environ['MFINPUTS'] 
+        os.environ['MFINPUTS'] = os.pathsep + t + \
+                                 os.path.join(this.get('root'), 'mf')
 
         if os.environ.has_key('TMP'):
             this.__set('tmp',os.environ['TMP'],'environment')
@@ -505,8 +508,7 @@ class Properties:
         """
 
         if os.name == 'nt':
-            path = os.path.join(this.get('root'), 'share', 'lilypond',
-                                'tex', var)
+            path = os.path.join(this.get('root'), 'tex', var)
         else:
             path =''
             cmd =('kpsewhich tex %s %s' % (var,errorlog))
@@ -514,8 +516,7 @@ class Properties:
             path = pipe.readline ()[:-1] # chop off \n
             return_status =  pipe.close()
             if return_status and not path:
-                path = os.path.join(this.get('root'), 'share', 'lilypond',
-                                    'tex', var)
+                path = os.path.join(this.get('root'), 'tex', var)
        fd = open(path, 'r')
         return fd
 
@@ -554,7 +555,7 @@ class Properties:
         else: # Windows apps like edit choke on .lilyrc
             dotFilename='_lilyrc'
 
-       for d in [os.path.join(this.get('root'),'share','lilypond','ly'), \
+       for d in [os.path.join(this.get('root'),'ly'), \
                   os.environ['HOME'], os.curdir ]:
            file=os.path.join(d,dotFilename)
            try:
@@ -674,7 +675,7 @@ class Properties:
            else:
                sys.exit('ExitBadWidth', m.group(2))
        else:           
-           sys.exit('ExitBadWidth', size)
+           sys.stderr.write ('ly2dvi: warning: ignoring linewidth: ' + size + '\n')
 
     #
     # setOrientation
@@ -876,7 +877,7 @@ class Properties:
 def getLilyopts():
     inc = ''   
     if len(Props.get('include')) > 0: 
-        inc = '-I ' + string.join(Props.get('include'),os.pathsep)
+        inc = string.join (map (lambda x: '-I "%s"' % x, Props.get('include')))
     else:
 
         if Props.get('dependencies'):
@@ -1016,14 +1017,29 @@ def main():
             type = infile.type()
             infile.close()
             if type == 'source':
-                cmd = 'lilypond %s %s 2>&1' % (getLilyopts(), file)
-                fd = os.popen( cmd , 'r' )
+                if os.environ.has_key('OS') and \
+                   os.environ['OS'] == 'Windows_95':
+                    cmd = 'ash -c "lilypond %s %s 2>&1"' %(getLilyopts(), file)
+                else:
+                    cmd = 'lilypond %s %s 2>&1' % (getLilyopts(), file)
+               sys.stderr.write ('executing: %s\n'% cmd)
+               
+                fd = os.popen(cmd , 'r')
                 log = ''
-                line=fd.readline()
-                while line:
-                    log = log + line
-                    sys.stderr.write( line )
-                    line=fd.readline()
+               
+               s = fd.readline()
+               while len(s) > 0:
+                       sys.stderr.write (s)
+                       sys.stderr.flush ()
+                       log = log + s
+                       s = fd.readline ()
+               if 0:
+                       s = fd.read (1)
+                       while len(s) > 0:
+                               sys.stderr.write (s)
+                               sys.stderr.flush ()
+                               s = fd.read (1)                 
+                       log = log + s
                 stat = fd.close()
                 if stat:
                     sys.exit('ExitBadLily', cmd )