]> git.lyx.org Git - lyx.git/blobdiff - lib/configure.py
Keep a copy of output from lib/configure.py to configure.log
[lyx.git] / lib / configure.py
index 0b866144cccf901e452230ebeac3293bfe6f6dd4..af20febd5e1e1af964ce866cfa3b9b17c250fb79 100644 (file)
 import sys, os, re, shutil, glob
 
 
+class Tee:
+    ''' Writing to a Tee object will write to all file objects it keeps.
+        That is to say, writing to Tee(sys.stdout, open(logfile, 'w')) will
+        write to sys.stdout as well as a log file.
+    '''
+    def __init__(self, *args):
+        self.files = args
+
+    def write(self, data):
+        for f in self.files:
+            result = f.write(data)
+        return result
+
+    def writelines(self, seq):
+        for i in seq:
+            self.write(i)
+
+
 def writeToFile(filename, lines, append = False):
     " utility function: write or append lines to filename "
     if append:
@@ -84,31 +102,21 @@ def checkTeXPaths():
     if os.name == 'nt' or sys.platform == 'cygwin':
         from tempfile import mkstemp
         fd, tmpfname = mkstemp(suffix='.ltx')
-        # a wrapper file
-        wfd, wtmpfname = mkstemp(suffix='.ltx')
         if os.name == 'nt':
             inpname = tmpfname.replace('\\', '/')
-            wtmpfname = wtmpfname.replace('\\', '/')
         else:
             inpname = cmdOutput('cygpath -m ' + tmpfname)
-            wtmpfname = cmdOutput('cygpath -m ' + wtmpfname)
-        os.write(fd, r'''
-\documentstyle{article}
-\begin{document}\end{document}
-    ''')
+        inpname = inpname.replace('~', '\\string~')
+        os.write(fd, r'\relax')
         os.close(fd)
-        os.write(wfd, r'\input{' + inpname.replace('~', '\\string~') + '}' )
-        os.close(wfd)
-        if cmdOutput('latex ' + wtmpfname).find('Error') != -1:
+        latex_out = cmdOutput(r'latex "\nonstopmode\input{%s}"' % inpname)
+        if 'Error' in latex_out:
             print "configure: TeX engine needs posix-style paths in latex files"
             windows_style_tex_paths = 'false'
         else:
             print "configure: TeX engine needs windows-style paths in latex files"
             windows_style_tex_paths = 'true'
-        tmpbname,ext = os.path.splitext(os.path.basename(tmpfname))
-        wtmpbname,ext = os.path.splitext(os.path.basename(wtmpfname))
-        removeFiles( [ tmpfname, wtmpfname, tmpbname + '.log', \
-           tmpbname + '.aux', wtmpbname + '.log', wtmpbname + '.aux' ] )
+        removeFiles([tmpfname, 'texput.log'])
     return windows_style_tex_paths
 
 
@@ -183,7 +191,7 @@ def checkLatex():
             checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']):
         # Windows only: DraftDVI
         converter_entry = r'''\converter latex      dvi2       "%%"    "latex"
-\converter dvi2       dvi        "python $$s/scripts/clean_dvi.py $$i $$o"     ""'''
+\converter dvi2       dvi        "python -tt $$s/scripts/clean_dvi.py $$i $$o" ""'''
     else:
         converter_entry = r'\converter latex      dvi        "%%"      "latex"'
     path, LATEX = checkProg('a Latex2e program', ['pplatex $$i', 'latex $$i', 'latex2e $$i'],
@@ -250,6 +258,9 @@ def checkFormatEntries():
 \Format linuxdoc   sgml    LinuxDoc               x  ""        "%%"    "document"
 \Format pdflatex   tex    "LaTeX (pdflatex)"      "" ""        "%%"    "document"
 \Format text       txt    "Plain text"            a  ""        "%%"    "document"
+\Format text2      txt    "Plain text (pstotext)" "" ""        "%%"    "document"
+\Format text3      txt    "Plain text (ps2ascii)" "" ""        "%%"    "document"
+\Format text4      txt    "Plain text (catdvi)"   "" ""        "%%"    "document"
 \Format textparagraph txt "Plain text (paragraphs)"    "" ""   "%%"    "document"''' ])
     #
     #checkProg('a Postscript interpreter', ['gs'],
@@ -335,6 +346,15 @@ def checkConverterEntries():
     checkProg('a PS to PDF converter', ['ps2pdf13 $$i $$o'],
         rc_entry = [ r'\converter ps         pdf        "%%"   ""' ])
     #
+    checkProg('a PS to TXT converter', ['pstotext $$i > $$o'],
+        rc_entry = [ r'\converter ps         text2      "%%"   ""' ])
+    #
+    checkProg('a PS to TXT converter', ['ps2ascii $$i $$o'],
+        rc_entry = [ r'\converter ps         text3      "%%"   ""' ])
+    #
+    checkProg('a DVI to TXT converter', ['catdvi $$i > $$o'],
+        rc_entry = [ r'\converter dvi        text4      "%%"   ""' ])
+    #
     checkProg('a DVI to PS converter', ['dvips -o $$o $$i'],
         rc_entry = [ r'\converter dvi        ps         "%%"   ""' ])
     #
@@ -343,7 +363,7 @@ def checkConverterEntries():
     #
     path, dvipng = checkProg('dvipng', ['dvipng'])
     if dvipng == "dvipng":
-        addToRC(r'\converter lyxpreview png        "python $$s/scripts/lyxpreview2bitmap.py"   ""')
+        addToRC(r'\converter lyxpreview png        "python -tt $$s/scripts/lyxpreview2bitmap.py"       ""')
     else:
         addToRC(r'\converter lyxpreview png        ""  ""')
     #  
@@ -387,13 +407,13 @@ def checkConverterEntries():
     # checkProg('Image converter', ['convert $$i $$o'])
     #
     # Entried that do not need checkProg
-    addToRC(r'''\converter lyxpreview ppm        "python $$s/scripts/lyxpreview2bitmap.py"     ""
+    addToRC(r'''\converter lyxpreview ppm        "python -tt $$s/scripts/lyxpreview2bitmap.py" ""
 \converter date       dateout    "date +%d-%m-%Y > $$o"        ""
 \converter docbook    docbook-xml "cp $$i $$o" "xml"
-\converter fen        asciichess "python $$s/scripts/fen2ascii.py $$i $$o"     ""
-\converter fig        pdftex     "python $$s/scripts/fig2pdftex.py $$i $$o"    ""
-\converter fig        pstex      "python $$s/scripts/fig2pstex.py $$i $$o"     ""
-\converter lyx        lyx13x     "python $$s/lyx2lyx/lyx2lyx -t 221 $$i > $$o" ""
+\converter fen        asciichess "python -tt $$s/scripts/fen2ascii.py $$i $$o" ""
+\converter fig        pdftex     "python -tt $$s/scripts/fig2pdftex.py $$i $$o"        ""
+\converter fig        pstex      "python -tt $$s/scripts/fig2pstex.py $$i $$o" ""
+\converter lyx        lyx13x     "python -tt $$s/lyx2lyx/lyx2lyx -t 221 $$i > $$o"     ""
 ''')
 
 
@@ -456,9 +476,9 @@ def checkOtherEntries():
 \print_spool_command "lpr"''',
             ''])
     # Add the rest of the entries (no checkProg is required)
-    addToRC(r'''\copier    fig        "python $$s/scripts/fig_copy.py $$i $$o"
-\copier    pstex      "python $$s/scripts/tex_copy.py $$i $$o $$l"
-\copier    pdftex     "python $$s/scripts/tex_copy.py $$i $$o $$l"
+    addToRC(r'''\copier    fig        "python -tt $$s/scripts/fig_copy.py $$i $$o"
+\copier    pstex      "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
+\copier    pdftex     "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
 ''')
 
 
@@ -506,7 +526,7 @@ def checkLatexConfig(check_config, bool_docbook, bool_linuxdoc):
 # This file declares layouts and their associated definition files
 # (include dir. relative to the place where this file is).
 # It contains only default values, since chkconfig.ltx could not be run
-# for some reason. Run ./configure if you need to update it after a
+# for some reason. Run ./configure.py if you need to update it after a
 # configuration change.
 ''')
         # build the list of available layout files and convert it to commands
@@ -563,9 +583,14 @@ def checkLatexConfig(check_config, bool_docbook, bool_linuxdoc):
         cl.close()
         #
         # we have chklayouts.tex, then process it
-        for line in cmdOutput(LATEX + ' wrap_chkconfig.ltx').splitlines():
+        fout = os.popen(LATEX + ' wrap_chkconfig.ltx')
+        while True:
+            line = fout.readline()
+            if not line:
+                break;
             if re.match('^\+', line):
-                print line
+                print line,
+        fout.close()
         #
         # currently, values in chhkconfig are only used to set
         # \font_encoding
@@ -596,7 +621,7 @@ def createLaTeXConfig():
         writeToFile('packages.lst', '''
 ### This file should contain the list of LaTeX packages that have been
 ### recognized by LyX. Unfortunately, since configure could not find
-### your LaTeX2e program, the tests have not been run. Run ./configure
+### your LaTeX2e program, the tests have not been run. Run ./configure.py
 ### if you need to update it after a configuration change.
 ''')
     print 'creating doc/LaTeXConfig.lyx'
@@ -642,10 +667,11 @@ def checkTeXAllowSpaces():
     if lyx_check_config:
         print "Checking whether TeX allows spaces in file names... ",
         writeToFile('a b.tex', r'\message{working^^J}' )
-        # FIXME: the bsh version uses < /dev/null which is not portable.
-        # Can anyone confirm if this option (-interaction) is available
-        # at other flavor of latex as well? (MikTex/win, Web2C/linux are fine.) 
-        if ''.join(cmdOutput(LATEX + ' -interaction=nonstopmode "a b"')).find('working') != -1:
+        if os.name == 'nt':
+            latex_out = cmdOutput(LATEX + r""" "\nonstopmode\input{\"a b\"}" """)
+        else:
+            latex_out = cmdOutput(LATEX + r""" '\nonstopmode\input{"a b"}' """)
+        if 'working' in latex_out:
             print 'yes'
             tex_allows_spaces = 'true'
         else:
@@ -670,6 +696,7 @@ if __name__ == '__main__':
     rc_entries = ''
     lyx_keep_temps = False
     version_suffix = ''
+    logfile = 'configure.log'
     ## Parse the command line
     for op in sys.argv[1:]:   # default shell/for list is $*, the options
         if op in [ '-help', '--help', '-h' ]:
@@ -690,7 +717,11 @@ Options:
         else:
             print "Unknown option", op
             sys.exit(1)
-    #    
+    #
+    # set up log file for stdout and stderr
+    log = open(logfile, 'w')
+    sys.stdout = Tee(sys.stdout, log)
+    sys.stderr = Tee(sys.stderr, log)
     # check if we run from the right directory
     srcdir = os.path.dirname(sys.argv[0])
     if srcdir == '':
@@ -705,8 +736,8 @@ Options:
     writeToFile(outfile, '''# This file has been automatically generated by LyX' lib/configure.py
 # script. It contains default settings that have been determined by
 # examining your system. PLEASE DO NOT MODIFY ANYTHING HERE! If you
-# want to customize LyX, make a copy of the file LYXDIR/lyxrc as
-# ~/.lyx/lyxrc and edit this file instead. Any setting in lyxrc will
+# want to customize LyX, use LyX' Preferences dialog or modify directly 
+# the "preferences" file instead. Any setting in that file will
 # override the values given here.
 ''')
     # check latex