X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2FTeXFiles.py;h=aac29bc9d0e20c2c647586d27e00ef3608d933a8;hb=ed44bbddee012f1cb38752142aba8e068dce47d2;hp=375d88e389ae2aa30a1526a9ef618ee39d8dbcad;hpb=f58609c7656049eb42ac085f5a99b71fd002197f;p=lyx.git diff --git a/lib/scripts/TeXFiles.py b/lib/scripts/TeXFiles.py index 375d88e389..aac29bc9d0 100755 --- a/lib/scripts/TeXFiles.py +++ b/lib/scripts/TeXFiles.py @@ -1,13 +1,12 @@ -#!/usr/bin/env python -# -*- coding: iso-8859-15 -*- +# -*- coding: utf-8 -*- # file TeXFiles.py # This file is part of LyX, the document processor. # Licence details can be found in the file COPYING. -# \author Herbert Voß +# \author Herbert Voß # \author Jean-Marc Lasgouttes -# \author Jürgen Spitzmüller +# \author Jürgen Spitzmüller # \author Bo Peng # Full author contact details are available in file CREDITS. @@ -17,54 +16,60 @@ # TeX style files -> option sty # bibtex style files -> option bst # bibtex database files -> option bib +# biblatex bibstyles -> option bbx +# biblatex citestyles -> option cbx # # with the help # of kpsewhich and creates a -# bstFiles.lst, clsFiles.lst, styFiles.lst, bibFiles.lst +# bstFiles.lst, clsFiles.lst, styFiles.lst, bibFiles.lst, +# bbxFiles.lst, cbxFiles.lst # without any parameter all files are created. # # Herbert Voss # # Updates from Jean-Marc Lasgouttes. # -# bib support added by Juergen Spitzmueller (v0.3) +# bib, bbx and cbx support added by Juergen Spitzmueller (v0.4) # # translated to python by Bo Peng, so that the script only # relies on python and kpsewhich (no shell command is used). # +from __future__ import print_function import os, sys, re cls_stylefile = 'clsFiles.lst' sty_stylefile = 'styFiles.lst' bst_stylefile = 'bstFiles.lst' bib_files = 'bibFiles.lst' +bbx_files = 'bbxFiles.lst' +cbx_files = 'cbxFiles.lst' def cmdOutput(cmd): - '''utility function: run a command and get its output as a string - cmd: command to run - ''' - fout = os.popen(cmd) - output = fout.read() - fout.close() - return output + '''utility function: run a command and get its output as a string + cmd: command to run + ''' + fout = os.popen(cmd) + output = fout.read() + fout.close() + return output # processing command line options if len(sys.argv) > 1: - if sys.argv[1] in ['--help', '-help']: - print '''Usage: TeXFiles.py [-version | cls | sty | bst | bib ] - Default is without any Parameters, - so that all files will be created''' - sye.exit(0) - else: - types = sys.argv[1:] - for type in types: - if type not in ['cls', 'sty', 'bst', 'bib']: - print 'ERROR: unknown type', type - sys.exit(1) + if sys.argv[1] in ['--help', '-help']: + print('''Usage: TeXFiles.py [-version | cls | sty | bst | bib | bbx| cbx ] + Default is without any Parameters, + so that all files will be created''') + sys.exit(0) + else: + types = sys.argv[1:] + for type in types: + if type not in ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx']: + print('ERROR: unknown type', type) + sys.exit(1) else: - # if no parameter is specified, assume all - types = ['cls', 'sty', 'bst', 'bib'] + # if no parameter is specified, assume all + types = ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx'] # # MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate @@ -73,44 +78,49 @@ else: # Create a variable that holds the right character to be used by the scripts. path_sep = os.pathsep if sys.platform == 'cygwin': - # MikTeX's kpsewhich says "kpathsea emulation version x.x.x", whereas - # teTeX's simply "kpathsea version x.x.x". - if 'emulation' in cmdOutput('kpsewhich --version'): - path_sep = ';' - else: - path_sep = ':' + if ';' in cmdOutput('kpsewhich --show-path=.tex'): + path_sep = ';' + else: + path_sep = ':' # process each file type for type in types: - print "Indexing files of type", type - if type == 'cls': - outfile = cls_stylefile - kpsetype = '.tex' - elif type == 'sty': - outfile = sty_stylefile - kpsetype = '.tex' - elif type == 'bst': - outfile = bst_stylefile - kpsetype = '.bst' - elif type == 'bib': - outfile = bib_files - kpsetype = '.bib' + print("Indexing files of type", type) + if type == 'cls': + outfile = cls_stylefile + kpsetype = '.tex' + elif type == 'sty': + outfile = sty_stylefile + kpsetype = '.tex' + elif type == 'bst': + outfile = bst_stylefile + kpsetype = '.bst' + elif type == 'bib': + outfile = bib_files + kpsetype = '.bib' + elif type == 'bbx': + outfile = bbx_files + kpsetype = '.tex' + elif type == 'cbx': + outfile = cbx_files + kpsetype = '.tex' - dirs = cmdOutput('kpsewhich --show-path=' + kpsetype).replace('!!', '').strip() - # remove excessive // - dirs = re.sub('//+', '/', dirs) - - file_ext = '.' + type - out = open(outfile, 'w') - for dir in dirs.split(path_sep): - # for each valid directory - if os.path.isdir(dir): - # walk down the file hierarchy - for root,path,files in os.walk(dir): - # check file type - for file in files: - if len(file) > 4 and file[-4:] == file_ext: - # force the use of / since miktex uses / even under windows - print >> out, root.replace('\\', '/') + '/' + file - out.close() + dirs = cmdOutput('kpsewhich --show-path=' + kpsetype).replace('!!', '').strip() + # remove excessive // + dirs = re.sub('//+', '/', dirs) + + file_ext = '.' + type + out = open(outfile, 'w') + for dir in dirs.split(path_sep): + # for each valid directory + if not os.path.isdir(dir): + continue + # walk down the file hierarchy + for root,path,files in os.walk(dir): + # check file type + for file in files: + if len(file) > 4 and file[-4:] == file_ext: + # force the use of / since miktex uses / even under windows + print(root.replace('\\', '/') + '/' + file, file=out) + out.close()