# Full author contact details are available in file CREDITS.
from __future__ import print_function
-import glob, logging, os, re, shutil, subprocess, sys, stat
+import glob, logging, os, errno, re, shutil, subprocess, sys, stat
# set up logging
logging.basicConfig(level = logging.DEBUG,
try:
os.remove(file)
logger.debug('Removing file %s' % file)
- except:
- logger.debug('Failed to remove file %s' % file)
+ except OSError as e:
+ if e.errno == errno.ENOENT: # no such file or directory
+ logger.debug('No need to remove file %s (it does not exists)' % file)
+ elif e.errno == errno.EISDIR: # is a directory
+ logger.debug('Failed to remove file %s (it is a directory)' % file)
+ else:
+ logger.debug('Failed to remove file %s' % file)
pass
from tempfile import mkstemp
fd, tmpfname = mkstemp(suffix='.ltx')
if os.name == 'nt':
- from locale import getdefaultlocale
- language, encoding = getdefaultlocale()
- if encoding == None:
- encoding = 'latin1'
+ encoding = sys.getfilesystemencoding()
if sys.version_info[0] < 3:
inpname = shortPath(unicode(tmpfname, encoding)).replace('\\', '/')
else:
- inpname = shortPath(str(tmpfname, encoding)).replace('\\', '/')
+ inpname = shortPath(tmpfname).replace('\\', '/')
else:
inpname = cmdOutput('cygpath -m ' + tmpfname)
logname = os.path.basename(re.sub("(?i).ltx", ".log", inpname))
inpname = inpname.replace('~', '\\string~')
- os.write(fd, r'\relax')
+ os.write(fd, b'\\relax')
os.close(fd)
latex_out = cmdOutput(r'latex "\nonstopmode\input{%s}\makeatletter\@@end"'
% inpname)
def checkInkscape():
''' Check whether Inkscape is available and return the full path (Windows only) '''
- if os.name != 'nt':
+ ''' On Mac OS (darwin) a wrapper is used - therefore the version is checked '''
+ ''' The answer of the real inkscape is validated and a fake binary used if this fails '''
+ if sys.platform == 'darwin':
+ version_string = cmdOutput("inkscape --version")
+ match = re.match('^Inkscape', version_string)
+ if match:
+ return 'inkscape'
+ else:
+ return 'inkscape-binary'
+ elif os.name != 'nt':
return 'inkscape'
if sys.version_info[0] < 3:
import _winreg as winreg
return False
+texteditors = ['xemacs', 'gvim', 'kedit', 'kwrite', 'kate',
+ 'nedit', 'gedit', 'geany', 'leafpad', 'mousepad',
+ 'xed', 'notepad', 'WinEdt', 'WinShell', 'PSPad']
+
def checkFormatEntries(dtl_tools):
''' Check all formats (\Format entries) '''
checkViewerEditor('a Tgif viewer and editor', ['tgif'],
['gimp-remote', 'gimp'], rc_entry = [imageformats])
addToRC(imageformats % ((iv, ie)*10))
#
- checkViewerEditor('a text editor',
- ['xemacs', 'gvim', 'kedit', 'kwrite', 'kate',
- 'nedit', 'gedit', 'geany', 'leafpad', 'mousepad', 'xed', 'notepad'],
+ checkViewerEditor('a text editor', texteditors,
rc_entry = [r'''\Format asciichess asc "Plain text (chess output)" "" "" "%%" "" ""
\Format docbook sgml DocBook B "" "%%" "document,menu=export" ""
\Format docbook-xml xml "DocBook (XML)" "" "" "%%" "document,menu=export" "application/docbook+xml"
\Format platex tex "LaTeX (pLaTeX)" "" "" "%%" "document,menu=export" ""
\Format literate nw NoWeb N "" "%%" "document,menu=export" ""
\Format sweave Rnw "Sweave" S "" "%%" "document,menu=export" ""
+\Format sweave-ja Rnw "Sweave (Japanese)" S "" "%%" "document,menu=export" ""
\Format r R "R/S code" "" "" "%%" "document,menu=export" ""
\Format knitr Rnw "Rnw (knitr)" "" "" "%%" "document,menu=export" ""
-\Format lilypond ly "LilyPond music" "" "" "%%" "vector" "text/x-lilypond"
+\Format knitr-ja Rnw "Rnw (knitr, Japanese)" "" "" "%%" "document,menu=export" ""
\Format lilypond-book lytex "LilyPond book (LaTeX)" "" "" "%%" "document,menu=export" ""
+\Format lilypond-book-ja lytex "LilyPond book (pLaTeX)" "" "" "%%" "document,menu=export" ""
\Format latex tex "LaTeX (plain)" L "" "%%" "document,menu=export" "text/x-tex"
\Format luatex tex "LaTeX (LuaTeX)" "" "" "%%" "document,menu=export" ""
\Format pdflatex tex "LaTeX (pdflatex)" "" "" "%%" "document,menu=export" ""
\Format text4 txt "Plain text (catdvi)" "" "" "%%" "document" ""
\Format textparagraph txt "Plain Text, Join Lines" "" "" "%%" "document" ""
\Format beamer.info pdf.info "Info (Beamer)" "" "" "%%" "document,menu=export" ""''' ])
+ #Lilypond files have special editors, but fall back to plain text editors
+ checkViewerEditor('a lilypond editor',
+ ['frescobaldi'] + texteditors,
+ rc_entry = [r'''\Format lilypond ly "LilyPond music" "" "" "%%" "vector" "text/x-lilypond"''' ])
#Spreadsheets using ssconvert from gnumeric
checkViewer('gnumeric spreadsheet software', ['gnumeric'],
rc_entry = [r'''\Format gnumeric gnumeric "Gnumeric spreadsheet" "" "" "%%" "document" "application/x-gnumeric"
#
checkEditor('a BibTeX editor', ['jabref', 'JabRef',
'pybliographic', 'bibdesk', 'gbib', 'kbib',
- 'kbibtex', 'sixpack', 'bibedit', 'tkbibtex'
- 'xemacs', 'gvim', 'kedit', 'kwrite', 'kate',
- 'jedit', 'TeXnicCenter', 'WinEdt', 'WinShell', 'PSPad',
- 'nedit', 'gedit', 'notepad', 'geany', 'leafpad', 'mousepad'],
+ 'kbibtex', 'sixpack', 'bibedit', 'tkbibtex', 'TeXnicCenter'] +
+ texteditors,
rc_entry = [r'''\Format bibtex bib "BibTeX" "" "" "%%" "" "text/x-bibtex"''' ])
#
#checkProg('a Postscript interpreter', ['gs'],
\Format eps3 eps "EPS (cropped)" "" "%%" "" "document" ""
\Format ps ps Postscript t "%%" "" "document,vector,menu=export" "application/postscript"'''])
# for xdg-open issues look here: http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg151818.html
+ # maybe use "bestApplication()" from https://github.com/jleclanche/python-mime
# the MIME type is set for pdf6, because that one needs to be autodetectable by libmime
checkViewer('a PDF previewer',
['pdfview', 'kpdf', 'okular', 'qpdfview --unique',
checkProg('a Sweave -> LaTeX converter', ['Rscript --verbose --no-save --no-restore $$s/scripts/lyxsweave.R $$p$$i $$p$$o $$e $$r'],
rc_entry = [r'''\converter sweave latex "%%" "needauth"
\converter sweave pdflatex "%%" "needauth"
+\converter sweave-ja platex "%%" "needauth"
\converter sweave xetex "%%" "needauth"
\converter sweave luatex "%%" "needauth"
\converter sweave dviluatex "%%" "needauth"'''])
checkProg('a knitr -> LaTeX converter', ['Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i $$p$$o $$e $$r'],
rc_entry = [r'''\converter knitr latex "%%" "needauth"
\converter knitr pdflatex "%%" "needauth"
+\converter knitr-ja platex "%%" "needauth"
\converter knitr xetex "%%" "needauth"
\converter knitr luatex "%%" "needauth"
\converter knitr dviluatex "%%" "needauth"'''])
#
checkProg('a Sweave -> R/S code converter', ['Rscript --verbose --no-save --no-restore $$s/scripts/lyxstangle.R $$i $$e $$r'],
- rc_entry = [ r'\converter sweave r "%%" "needauth"' ])
+ rc_entry = [ r'\converter sweave r "%%" "needauth"',
+ r'\converter sweave-ja r "%%" "needauth"' ])
#
checkProg('a knitr -> R/S code converter', ['Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i $$p$$o $$e $$r tangle'],
- rc_entry = [ r'\converter knitr r "%%" "needauth"' ])
+ rc_entry = [ r'\converter knitr r "%%" "needauth"',
+ r'\converter knitr-ja r "%%" "needauth"' ])
#
checkProg('an HTML -> LaTeX converter', ['html2latex $$i', 'gnuhtml2latex',
'htmltolatex -input $$i -output $$o', 'htmltolatex.jar -input $$i -output $$o'],
# Only define a converter from pdf6 for graphics
checkProg('a PDF to EPS converter', ['pdftops -eps -f 1 -l 1 $$i $$o'],
rc_entry = [ r'\converter pdf6 eps "%%" ""' ])
+ # Define a converter from pdf6 to png for Macs where pdftops is missing.
+ # The converter utility sips allows to force the dimensions of the resulting
+ # png image. The value of 800 pixel for the width is arbitrary and not
+ # related to the current screen resolution or width.
+ # There is no converter parameter for this information.
+ checkProg('a PDF to PNG converter',
+ ['sips --resampleWidth 800 --setProperty format png $$i --out $$o'],
+ rc_entry = [ r'\converter pdf6 png "%%" ""' ])
# Create one converter for a PDF produced using TeX fonts and one for a
# PDF produced using non-TeX fonts. This does not produce non-unique
# conversion paths, since a given document either uses TeX fonts or not.
\converter fig ppm "fig2dev -L ppm $$i $$o" ""
\converter fig svg "fig2dev -L svg $$i $$o" ""
\converter fig png "fig2dev -L png $$i $$o" ""
-\converter svg pdftex "python -tt $$s/scripts/svg2pdftex.py $$i $$o" ""
-\converter svg pstex "python -tt $$s/scripts/svg2pstex.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" ""''')
#
+ checkProg('a SVG -> PDFTeX converter', [inkscape_name],
+ rc_entry = [ r'\converter svg pdftex "python -tt $$s/scripts/svg2pdftex.py %% $$p$$i $$p$$o" ""'],
+ path = [inkscape_path])
+ #
+ checkProg('a SVG -> PSTeX converter', [inkscape_name],
+ rc_entry = [ r'\converter svg pstex "python -tt $$s/scripts/svg2pstex.py %% $$p$$i $$p$$o" ""'],
+ path = [inkscape_path])
+ #
checkProg('a TIFF -> PS converter', ['tiff2ps $$i > $$o'],
rc_entry = [ r'\converter tiff eps "%%" ""'])
#
\converter tgif png "tgif -print -color -png -o $$d $$i" ""
\converter tgif pdf6 "tgif -print -color -pdf -stdout $$i > $$o" ""'''])
#
- checkProg('a WMF -> EPS converter', ['metafile2eps $$i $$o', 'wmf2eps -o $$o $$i', inkscape_name + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
+ checkProg('a WMF -> EPS converter', ['metafile2eps $$i $$o', 'wmf2eps -o $$o $$i', inkscape_name + ' --file=$$p$$i --export-area-drawing --without-gui --export-eps=$$p$$o'],
rc_entry = [ r'\converter wmf eps "%%" ""'])
#
- checkProg('an EMF -> EPS converter', ['metafile2eps $$i $$o', 'wmf2eps -o $$o $$i', inkscape_name + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
+ checkProg('an EMF -> EPS converter', ['metafile2eps $$i $$o', 'wmf2eps -o $$o $$i', inkscape_name + ' --file=$$p$$i --export-area-drawing --without-gui --export-eps=$$p$$o'],
rc_entry = [ r'\converter emf eps "%%" ""'])
#
- checkProg('a WMF -> PDF converter', [inkscape_name + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
+ checkProg('a WMF -> PDF converter', [inkscape_name + ' --file=$$p$$i --export-area-drawing --without-gui --export-pdf=$$p$$o'],
rc_entry = [ r'\converter wmf pdf6 "%%" ""'])
#
- checkProg('an EMF -> PDF converter', [inkscape_name + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
+ checkProg('an EMF -> PDF converter', [inkscape_name + ' --file=$$p$$i --export-area-drawing --without-gui --export-pdf=$$p$$o'],
rc_entry = [ r'\converter emf pdf6 "%%" ""'])
# Only define a converter to pdf6 for graphics
checkProg('an EPS -> PDF converter', ['epstopdf'],
# The eps2->eps converter then fixes the bounding box by cropping.
# Although unoconv can convert to png and pdf as well, do not define
# odg->png and odg->pdf converters, since the bb would be too large as well.
- checkProg('an OpenDocument -> EPS converter', ['libreoffice -headless -nologo -convert-to eps $$i', 'unoconv -f eps --stdout $$i > $$o'],
+ checkProg('an OpenDocument -> EPS converter', ['libreoffice --headless --nologo --convert-to eps $$i', 'unoconv -f eps --stdout $$i > $$o'],
rc_entry = [ r'\converter odg eps2 "%%" ""'])
#
checkProg('a SVG (compressed) -> SVG converter', ['gunzip -c $$i > $$o'],
rc_entry = [ r'\converter svg svgz "%%" ""'])
# Only define a converter to pdf6 for graphics
# Prefer rsvg-convert over inkscape since it is faster (see http://www.lyx.org/trac/ticket/9891)
- checkProg('a SVG -> PDF converter', ['rsvg-convert -f pdf -o $$o $$i', inkscape_name + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
+ checkProg('a SVG -> PDF converter', ['rsvg-convert -f pdf -o $$o $$i', inkscape_name + ' --file=$$p$$i --export-area-drawing --without-gui --export-pdf=$$p$$o'],
rc_entry = [ r'''\converter svg pdf6 "%%" ""
\converter svgz pdf6 "%%" ""'''],
path = ['', inkscape_path])
#
- checkProg('a SVG -> EPS converter', ['rsvg-convert -f ps -o $$o $$i', inkscape_name + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
+ checkProg('a SVG -> EPS converter', ['rsvg-convert -f ps -o $$o $$i', inkscape_name + ' --file=$$p$$i --export-area-drawing --without-gui --export-eps=$$p$$o'],
rc_entry = [ r'''\converter svg eps "%%" ""
\converter svgz eps "%%" ""'''],
path = ['', inkscape_path])
rc_entry = [ r'''\converter svg png "%%" "",
\converter svgz png "%%" ""'''],
path = ['', inkscape_path])
-
+ #
+ checkProg('Gnuplot', ['gnuplot'],
+ rc_entry = [ r'''\Format gnuplot "gp, gnuplot" "Gnuplot" "" "" "" "vector" "text/plain"
+\converter gnuplot pdf6 "python -tt $$s/scripts/gnuplot2pdf.py $$i $$o" "needauth"''' ])
#
# gnumeric/xls/ods to tex
checkProg('a spreadsheet -> latex converter', ['ssconvert'],
# this, use different output folders for eps and pdf outputs.
addToRC(r'\converter lilypond-book latex "lilypond-book --safe --lily-output-dir=ly-eps $$i" ""')
addToRC(r'\converter lilypond-book pdflatex "lilypond-book --safe --pdf --latex-program=pdflatex --lily-output-dir=ly-pdf $$i" ""')
+ addToRC(r'\converter lilypond-book-ja platex "lilypond-book --safe --pdf --latex-program=platex --lily-output-dir=ly-pdf $$i" ""')
addToRC(r'\converter lilypond-book xetex "lilypond-book --safe --pdf --latex-program=xelatex --lily-output-dir=ly-pdf $$i" ""')
addToRC(r'\converter lilypond-book luatex "lilypond-book --safe --pdf --latex-program=lualatex --lily-output-dir=ly-pdf $$i" ""')
addToRC(r'\converter lilypond-book dviluatex "lilypond-book --safe --latex-program=dvilualatex --lily-output-dir=ly-eps $$i" ""')
rc_entry = [ r'\chktex_command "%%"' ])
checkProgAlternatives('BibTeX or alternative programs',
['bibtex', 'bibtex8', 'biber'],
- rc_entry = [ r'\bibtex_command "%%"' ],
+ rc_entry = [ r'\bibtex_command "automatic"' ],
alt_rc_entry = [ r'\bibtex_alternatives "%%"' ])
- checkProg('a specific Japanese BibTeX variant',
- ['pbibtex', 'jbibtex', 'bibtex'],
- rc_entry = [ r'\jbibtex_command "%%"' ])
+ checkProgAlternatives('a specific Japanese BibTeX variant',
+ ['pbibtex', 'upbibtex', 'jbibtex', 'bibtex', 'biber'],
+ rc_entry = [ r'\jbibtex_command "automatic"' ],
+ alt_rc_entry = [ r'\jbibtex_alternatives "%%"' ])
checkProgAlternatives('available index processors',
['texindy', 'makeindex -c -q', 'xindy'],
rc_entry = [ r'\index_command "%%"' ],
'splitindex.class'], rc_entry = [ r'\splitindex_command "%%"' ])
checkProg('a nomenclature processor', ['makeindex'],
rc_entry = [ r'\nomencl_command "makeindex -s nomencl.ist"' ])
+ checkProg('a python-pygments driver command', ['pygmentize'],
+ rc_entry = [ r'\pygmentize_command "%%"' ])
## FIXME: OCTAVE is not used anywhere
# path, OCTAVE = checkProg('Octave', ['octave'])
## FIXME: MAPLE is not used anywhere
# Construct the list of classes to test for.
# build the list of available layout files and convert it to commands
# for chkconfig.ltx
- declare = re.compile(r'^\s*#\s*\\Declare(LaTeX|DocBook)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}\s*$')
- category = re.compile(r'^\s*#\s*\\DeclareCategory{(.*)}\s*$')
- empty = re.compile(r'^\s*$')
+ declare = re.compile(b'^\\s*#\\s*\\\\Declare(LaTeX|DocBook)Class\\s*(\[([^,]*)(,.*)*\])*\\s*{(.*)}\\s*$')
+ category = re.compile(b'^\\s*#\\s*\\\\DeclareCategory{(.*)}\\s*$')
+ empty = re.compile(b'^\\s*$')
testclasses = list()
for file in (glob.glob( os.path.join('layouts', '*.layout') )
+ glob.glob( os.path.join(srcdir, 'layouts', '*.layout' ) ) ):
if not os.path.isfile(file):
continue
classname = file.split(os.sep)[-1].split('.')[0]
- decline = ""
- catline = ""
- for line in open(file).readlines():
- if not empty.match(line) and line[0] != '#':
- if decline == "":
+ decline = b""
+ catline = b""
+ for line in open(file, 'rb').readlines():
+ if not empty.match(line) and line[0] != b'#'[0]:
+ if decline == b"":
logger.warning("Failed to find valid \Declare line "
"for layout file `%s'.\n\t=> Skipping this file!" % file)
nodeclaration = True
# A class, but no category declaration. Just break.
break
if declare.search(line) != None:
- decline = "\\TestDocClass{%s}{%s}" % (classname, line[1:].strip())
+ decline = b"\\TestDocClass{%s}{%s}" \
+ % (classname.encode('ascii'), line[1:].strip())
testclasses.append(decline)
elif category.search(line) != None:
- catline = ("\\DeclareCategory{%s}{%s}"
- % (classname, category.search(line).groups()[0]))
+ catline = (b"\\DeclareCategory{%s}{%s}"
+ % (classname.encode('ascii'),
+ category.search(line).groups()[0]))
testclasses.append(catline)
- if catline == "" or decline == "":
+ if catline == b"" or decline == b"":
continue
break
if nodeclaration:
continue
testclasses.sort()
- cl = open('chklayouts.tex', 'w')
+ cl = open('chklayouts.tex', 'wb')
for line in testclasses:
- cl.write(line + '\n')
+ cl.write(line + b'\n')
cl.close()
#
# we have chklayouts.tex, then process it
return '"%s" "%s" "%s" "%s" "%s" "%s" "%s"\n' % (modname, filename, cet, cfm, db, desc, pkgs)
+def checkXTemplates():
+ removeFiles(['xtemplates.lst'])
+
+ logger.info('+checking list of external templates... ')
+ tx = open('xtemplates.lst', 'w')
+ tx.write('''## This file lists external templates.
+## It has been automatically generated by configure
+## Use "Options/Reconfigure" if you need to update it after a
+## configuration change.
+''')
+
+ # build the list of available templates
+ seen = []
+ # note that this searches the local directory first, then the
+ # system directory. that way, we pick up the user's version first.
+ for file in glob.glob( os.path.join('xtemplates', '*.xtemplate') ) + \
+ glob.glob( os.path.join(srcdir, 'xtemplates', '*.xtemplate' ) ) :
+ # valid file?
+ logger.info(file)
+ if not os.path.isfile(file):
+ continue
+
+ filename = file.split(os.sep)[-1]
+ if seen.count(filename):
+ continue
+
+ seen.append(filename)
+ if filename != "":
+ tx.write(filename + "\n")
+ tx.close()
+ logger.info('\tdone')
+
+
def checkTeXAllowSpaces():
''' Let's check whether spaces are allowed in TeX file names '''
tex_allows_spaces = 'false'
lyx_check_config = True
lyx_kpsewhich = True
outfile = 'lyxrc.defaults'
- lyxrc_fileformat = 20
+ lyxrc_fileformat = 24
rc_entries = ''
lyx_keep_temps = False
version_suffix = ''
rescanTeXFiles()
checkModulesConfig()
checkCiteEnginesConfig()
+ checkXTemplates()
# --without-latex-config can disable lyx_check_config
ret = checkLatexConfig(lyx_check_config and LATEX != '', bool_docbook)
removeTempFiles()