]> git.lyx.org Git - lyx.git/blobdiff - lib/configure.py
configure.py: add support for Python 3 on Windows
[lyx.git] / lib / configure.py
index e43e1b5774e83f6eb61aa464ea240eb0a4cba99a..be47cea7a08252a0b0ccc61a186854204dd66678 100644 (file)
@@ -9,7 +9,7 @@
 # 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,
@@ -196,19 +196,16 @@ def checkTeXPaths():
         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)
@@ -1352,7 +1349,11 @@ def checkLatexConfig(check_config, bool_docbook):
         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 "
@@ -1663,6 +1664,39 @@ def processCiteEngineFile(file, filename, bool_docbook):
     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'
@@ -1786,6 +1820,7 @@ Format %i
         rescanTeXFiles()
     checkModulesConfig()
     checkCiteEnginesConfig()
+    checkXTemplates()
     # --without-latex-config can disable lyx_check_config
     ret = checkLatexConfig(lyx_check_config and LATEX != '', bool_docbook)
     removeTempFiles()