# 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, re, shutil, subprocess, sys, stat, io
# set up logging
logging.basicConfig(level = logging.DEBUG,
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)
classname = file.split(os.sep)[-1].split('.')[0]
decline = ""
catline = ""
- for line in open(file).readlines():
+ if os.name == 'nt':
+ enco = sys.getfilesystemencoding()
+ else:
+ enco="utf8"
+ for line in io.open(file, encoding=enco).readlines():
if not empty.match(line) and line[0] != '#':
if decline == "":
logger.warning("Failed to find valid \Declare line "
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'
rescanTeXFiles()
checkModulesConfig()
checkCiteEnginesConfig()
+ checkXTemplates()
# --without-latex-config can disable lyx_check_config
ret = checkLatexConfig(lyx_check_config and LATEX != '', bool_docbook)
removeTempFiles()