X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fconfigure.py;h=29c4bbc5e01713d0fbcb6b4eef29a43c8fef3f16;hb=21e8d10d975b37882d5f3fb7862a3fcb5616640d;hp=463f57aee67c36070bc5e1a6cc1a2e5381829996;hpb=4ae87a3bb8503b5a672bb85448b11f08ebcfeffd;p=lyx.git diff --git a/lib/configure.py b/lib/configure.py index 463f57aee6..29c4bbc5e0 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python -tt +#! /usr/bin/env python # # file configure.py # This file is part of LyX, the document processor. @@ -13,6 +13,24 @@ 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 @@ -212,13 +220,13 @@ def checkLatex(): def checkFormatEntries(): ''' Check all formats (\Format entries) ''' checkViewer('a Tgif viewer and editor', ['tgif'], - rc_entry = [r'\Format tgif obj Tgif "" "%%" "%%" ""']) + rc_entry = [r'\Format tgif obj Tgif "" "%%" "%%" "vector"']) # checkViewer('a FIG viewer and editor', ['xfig'], - rc_entry = [r'\Format fig fig FIG "" "%%" "%%" ""']) + rc_entry = [r'\Format fig fig FIG "" "%%" "%%" "vector"']) # checkViewer('a Grace viewer and editor', ['xmgrace'], - rc_entry = [r'\Format agr agr Grace "" "%%" "%%" ""']) + rc_entry = [r'\Format agr agr Grace "" "%%" "%%" "vector"']) # checkViewer('a FEN viewer and editor', ['xboard -lpf $$i -mode EditPosition'], rc_entry = [r'\Format fen fen FEN "" "%%" "%%" ""']) @@ -246,31 +254,35 @@ def checkFormatEntries(): \Format docbook sgml DocBook B "" "%%" "document" \Format docbook-xml xml "Docbook (XML)" "" "" "%%" "document" \Format literate nw NoWeb N "" "%%" "document" +\Format lilypond ly "LilyPond music" "" "" "%%" "vector" \Format latex tex "LaTeX (plain)" L "" "%%" "document" \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'], # rc_entry = [ r'\ps_command "%%"' ]) checkViewer('a Postscript previewer', ['gv', 'ghostview -swap', 'kghostview'], - rc_entry = [r'''\Format eps eps EPS "" "%%" "" "" -\Format ps ps Postscript t "%%" "" "document"''']) + rc_entry = [r'''\Format eps eps EPS "" "%%" "" "vector" +\Format ps ps Postscript t "%%" "" "document,vector"''']) # checkViewer('a PDF previewer', ['acrobat', 'acroread', 'gv', 'ghostview', \ 'xpdf', 'kpdf', 'kghostview'], - rc_entry = [r'''\Format pdf pdf "PDF (ps2pdf)" P "%%" "" "document" -\Format pdf2 pdf "PDF (pdflatex)" F "%%" "" "document" -\Format pdf3 pdf "PDF (dvipdfm)" m "%%" "" "document"''']) + rc_entry = [r'''\Format pdf pdf "PDF (ps2pdf)" P "%%" "" "document,vector" +\Format pdf2 pdf "PDF (pdflatex)" F "%%" "" "document,vector" +\Format pdf3 pdf "PDF (dvipdfm)" m "%%" "" "document,vector"''']) # checkViewer('a DVI previewer', ['xdvi', 'kdvi'], - rc_entry = [r'\Format dvi dvi DVI D "%%" "" "document"']) + rc_entry = [r'\Format dvi dvi DVI D "%%" "" "document,vector"']) if ((os.name == 'nt' or sys.platform == 'cygwin') and checkProg('DVI to DTL converter', ['dv2dt']) != ['', ''] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']): # Windows only: DraftDVI - addToRC(r'\Format dvi2 dvi DraftDVI "" "" "document"') + addToRC(r'\Format dvi2 dvi DraftDVI "" "" "document,vector"') # checkViewer('a HTML previewer', ['mozilla file://$$p$$i', 'netscape'], rc_entry = [r'\Format html html HTML H "%%" "" "document"']) @@ -284,8 +296,10 @@ def checkFormatEntries(): \Format pdftex pdftex_t PDFTEX "" "" "" "" \Format program "" Program "" "" "" "" \Format pstex pstex_t PSTEX "" "" "" "" -\Format sxw sxw "OpenOffice.Org Writer" O "" "" "document" -\Format word doc "MS Word" W "" "" "document" +\Format rtf rtf "Rich Text Format" "" "" "" "document,vector" +\Format sxw sxw "OpenOffice.Org Writer" O "" "" "document,vector" +\Format wmf wmf "Windows Meta File" "" "" "" "vector" +\Format word doc "MS Word" W "" "" "document,vector" \Format wordhtml html "MS Word (HTML)" "" "" "" "document" ''') @@ -304,15 +318,12 @@ def checkConverterEntries(): os.environ["PATH"] = os.path.join('..', 'src', 'tex2lyx') + \ os.pathsep + path_orig - checkProg('a LaTeX -> LyX converter', ['tex2lyx -f $$i $$o', \ - 'tex2lyx' + version_suffix + ' -f $$i $$o' ], - rc_entry = [ r'\converter latex lyx "%%" ""' ]) + checkProg('a LaTeX/Noweb -> LyX converter', ['tex2lyx', 'tex2lyx' + version_suffix], + rc_entry = [r'''\converter latex lyx "%% -f $$i $$o" "" +\converter literate lyx "%% -n -f $$i $$o" ""''']) os.environ["PATH"] = path_orig - # - checkProg('a Noweb -> LyX converter', ['noweb2lyx' + version_suffix + ' $$i $$o'], path = ['./reLyX'], - rc_entry = [ r'\converter literate lyx "%%" ""' ]) # checkProg('a Noweb -> LaTeX converter', ['noweave -delay -index $$i > $$o'], rc_entry = [ r'\converter literate latex "%%" ""' ]) @@ -329,12 +340,24 @@ def checkConverterEntries(): checkProg('an OpenOffice.org -> LaTeX converter', ['w2l -clean $$i'], rc_entry = [ r'\converter sxw latex "%%" ""' ]) # - checkProg('an LaTeX -> OpenOffice.org LaTeX converter', ['oolatex $$i', 'oolatex.sh $$i'], + checkProg('a LaTeX -> OpenOffice.org converter', ['oolatex $$i', 'oolatex.sh $$i'], rc_entry = [ r'\converter latex sxw "%%" "latex"' ]) + # On windows it is called latex2rt.exe + checkProg('a LaTeX -> RTF converter', ['latex2rtf -p -S -o $$o $$i', 'latex2rt -p -S -o $$o $$i'], + rc_entry = [ r'\converter latex rtf "%%" "needaux"' ]) # 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 "%%" ""' ]) # @@ -368,6 +391,9 @@ def checkConverterEntries(): \converter tgif pdf "tgif -stdout -print -color -pdf $$i > $$o" ""''', '']) # + checkProg('a WMF -> EPS converter', ['wmf2eps -o $$o $$i'], + rc_entry = [ r'\converter wmf eps "%%" ""', '']) + # checkProg('a EPS -> PDF converter', ['epstopdf'], rc_entry = [ r'\converter eps pdf "epstopdf --outfile=$$o $$i" ""', '']) # @@ -383,6 +409,24 @@ def checkConverterEntries(): 'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'], rc_entry = [ r'\converter latex html "%%" "originaldir,needaux"' ]) # + path, lilypond = checkProg('a LilyPond -> ESP/PDF/PNG converter', ['lilypond']) + if (lilypond != ''): + version_string = cmdOutput("lilypond --version") + match = re.match('GNU LilyPond (\S+)', version_string) + if match: + version_number = match.groups()[0] + version = version_number.split('.') + if int(version[0]) > 2 or (len(version) > 1 and int(version[0]) == 2 and int(version[1]) >= 6): + addToRC(r'''\converter lilypond eps "lilypond -b eps --ps $$i" "" +\converter lilypond png "lilypond -b eps --png $$i" ""''') + if int(version[0]) > 2 or (len(version) > 1 and int(version[0]) == 2 and int(version[1]) >= 9): + addToRC(r'\converter lilypond pdf "lilypond -b eps --pdf $$i" ""') + print '+ found LilyPond version %s.' % version_number + else: + print '+ found LilyPond, but version %s is too old.' % version_number + else: + print '+ found LilyPond, but could not extract version number.' + # # FIXME: no rc_entry? comment it out # checkProg('Image converter', ['convert $$i $$o']) # @@ -479,7 +523,7 @@ def processLayoutFile(file, bool_docbook, bool_linuxdoc): ''' classname = file.split(os.sep)[-1].split('.')[0] # return ('LaTeX', '[a,b]', 'a', ',b,c', 'article') for \DeclearLaTeXClass[a,b,c]{article} - p = re.compile(r'\Declare(LaTeX|DocBook|LinuxDoc)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}') + p = re.compile(r'\Declare(LaTeX|DocBook)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}') for line in open(file).readlines(): res = p.search(line) if res != None: @@ -506,7 +550,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 @@ -541,7 +585,7 @@ def checkLatexConfig(check_config, bool_docbook, bool_linuxdoc): # Construct the list of classes to test for. # build the list of available layout files and convert it to commands # for chkconfig.ltx - p1 = re.compile(r'\Declare(LaTeX|DocBook|LinuxDoc)Class') + p1 = re.compile(r'\Declare(LaTeX|DocBook)Class') testclasses = list() for file in glob.glob( os.path.join('layouts', '*.layout') ) + \ glob.glob( os.path.join(srcdir, 'layouts', '*.layout' ) ) : @@ -563,9 +607,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 +645,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 +691,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 +720,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 +741,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 +760,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