]> git.lyx.org Git - lyx.git/blobdiff - lib/configure.py
Update docs to 2.3.0alpha1 format
[lyx.git] / lib / configure.py
index 8a016a940399277c7f685e23cbd05fb3b2d39cfc..f995c62ca76f7f3b4674dd0fc080ee0a7a6ccad6 100644 (file)
@@ -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)
@@ -621,13 +618,18 @@ def checkFormatEntries(dtl_tools):
 \Format tiff       tif     TIFF                   "" "%s"      "%s"    ""      "image/tiff"
 \Format xbm        xbm     XBM                    "" "%s"      "%s"    ""      "image/x-xbitmap"
 \Format xpm        xpm     XPM                    "" "%s"      "%s"    ""      "image/x-xpixmap"'''
-    path, iv = checkViewerNoRC('a raster image viewer', ['xv', 'kview', 'gimp-remote', 'gimp'], rc_entry = [imageformats])
-    path, ie = checkEditorNoRC('a raster image editor', ['gimp-remote', 'gimp'], rc_entry = [imageformats])
-    addToRC(imageformats %
-        (iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie) )
-    #
-    checkViewerEditor('a text editor', ['xemacs', 'gvim', 'kedit', 'kwrite', 'kate',
-        'nedit', 'gedit', 'notepad', 'geany', 'leafpad', 'mousepad'],
+    path, iv = checkViewerNoRC('a raster image viewer',
+        ['xv', 'gwenview', 'kview',
+         'eog', 'xviewer', 'ristretto', 'gpicview', 'lximage-qt',
+         'xdg-open', 'gimp-remote', 'gimp'],
+        rc_entry = [imageformats])
+    path, ie = checkEditorNoRC('a raster image editor',
+        ['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'],
         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"
@@ -672,19 +674,22 @@ def checkFormatEntries(dtl_tools):
     #
     #checkProg('a Postscript interpreter', ['gs'],
     #  rc_entry = [ r'\ps_command "%%"' ])
-    checkViewer('a Postscript previewer', ['kghostview', 'okular', 'qpdfview --unique',
-                                           'evince', 'gv', 'ghostview -swap',
-                                           'gsview64', 'gsview32'],
+    checkViewer('a Postscript previewer',
+                ['kghostview', 'okular', 'qpdfview --unique',
+                 'evince', 'xreader',
+                 'gv', 'ghostview -swap', 'gsview64', 'gsview32'],
         rc_entry = [r'''\Format eps        eps     EPS                    "" "%%"      ""      "vector"        "image/x-eps"
 \Format eps2       eps    "EPS (uncropped)"       "" "%%"      ""      "vector"        ""
 \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',
-                                    'evince', 'kghostview', 'xpdf', 'SumatraPDF',
-                                    'acrobat', 'acroread', 'mupdf', 'gv',
-                                    'ghostview', 'AcroRd32', 'gsview64', 'gsview32'],
+    checkViewer('a PDF previewer',
+                ['pdfview', 'kpdf', 'okular', 'qpdfview --unique',
+                 'evince', 'xreader', 'kghostview', 'xpdf', 'SumatraPDF',
+                 'acrobat', 'acroread', 'mupdf',
+                 'gv', 'ghostview', 'AcroRd32', 'gsview64', 'gsview32'],
         rc_entry = [r'''\Format pdf        pdf    "PDF (ps2pdf)"          P  "%%"      ""      "document,vector,menu=export"   ""
 \Format pdf2       pdf    "PDF (pdflatex)"        F  "%%"      ""      "document,vector,menu=export"   ""
 \Format pdf3       pdf    "PDF (dvipdfm)"         m  "%%"      ""      "document,vector,menu=export"   ""
@@ -694,7 +699,9 @@ def checkFormatEntries(dtl_tools):
 \Format pdf7       pdf    "PDF (cropped)"         "" "%%"      ""      "document,vector"       ""
 \Format pdf8       pdf    "PDF (lower resolution)"         "" "%%"     ""      "document,vector"       ""'''])
     #
-    checkViewer('a DVI previewer', ['xdvi', 'kdvi', 'okular', 'yap', 'dviout -Set=!m'],
+    checkViewer('a DVI previewer', ['xdvi', 'kdvi', 'okular',
+                                    'evince', 'xreader',
+                                    'yap', 'dviout -Set=!m'],
         rc_entry = [r'''\Format dvi        dvi     DVI                    D  "%%"      ""      "document,vector,menu=export"   "application/x-dvi"
 \Format dvi3       dvi     "DVI (LuaTeX)"          V  "%%"     ""      "document,vector,menu=export"   ""'''])
     if dtl_tools:
@@ -1168,11 +1175,12 @@ def checkOtherEntries():
         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 "%%"' ],
@@ -1329,9 +1337,9 @@ def checkLatexConfig(check_config, bool_docbook):
     # 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' ) ) ):
@@ -1339,32 +1347,34 @@ def checkLatexConfig(check_config, bool_docbook):
         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
@@ -1652,6 +1662,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'
@@ -1702,7 +1745,7 @@ if __name__ == '__main__':
     lyx_check_config = True
     lyx_kpsewhich = True
     outfile = 'lyxrc.defaults'
-    lyxrc_fileformat = 20
+    lyxrc_fileformat = 21
     rc_entries = ''
     lyx_keep_temps = False
     version_suffix = ''
@@ -1775,6 +1818,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()