1 # -*- coding: utf-8 -*-
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
8 # \author Jean-Marc Lasgouttes
9 # \author Jürgen Spitzmüller
12 # Full author contact details are available in file CREDITS.
14 # all files -> without option
15 # TeX class files -> option cls
16 # TeX style files -> option sty
17 # bibtex style files -> option bst
18 # bibtex database files -> option bib
19 # biblatex bibstyles -> option bbx
20 # biblatex citestyles -> option cbx
23 # of kpsewhich and creates a
24 # bstFiles.lst, clsFiles.lst, styFiles.lst, bibFiles.lst,
25 # bbxFiles.lst, cbxFiles.lst
26 # without any parameter all files are created.
28 # Herbert Voss <voss@perce.org>
30 # Updates from Jean-Marc Lasgouttes.
32 # bib, bbx and cbx support added by Juergen Spitzmueller (v0.4)
34 # translated to python by Bo Peng, so that the script only
35 # relies on python and kpsewhich (no shell command is used).
38 from __future__ import print_function
41 cls_stylefile = 'clsFiles.lst'
42 sty_stylefile = 'styFiles.lst'
43 bst_stylefile = 'bstFiles.lst'
44 bib_files = 'bibFiles.lst'
45 bbx_files = 'bbxFiles.lst'
46 cbx_files = 'cbxFiles.lst'
49 '''utility function: run a command and get its output as a string
57 # processing command line options
59 if sys.argv[1] in ['--help', '-help']:
60 print('''Usage: TeXFiles.py [-version | cls | sty | bst | bib | bbx| cbx ]
61 Default is without any Parameters,
62 so that all files will be created''')
67 if type not in ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx']:
68 print('ERROR: unknown type', type)
71 # if no parameter is specified, assume all
72 types = ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx']
75 # MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate
76 # directories in path lists whereas Unix uses `:'. Make an exception for
77 # Cygwin, where we could have either teTeX (using `:') or MikTeX (using `;').
78 # Create a variable that holds the right character to be used by the scripts.
80 if sys.platform == 'cygwin':
81 if ';' in cmdOutput('kpsewhich --show-path=.tex'):
86 # process each file type
88 print("Indexing files of type", type)
90 outfile = cls_stylefile
93 outfile = sty_stylefile
96 outfile = bst_stylefile
108 dirs = cmdOutput('kpsewhich --show-path=' + kpsetype).replace('!!', '').strip()
109 # remove excessive //
110 dirs = re.sub('//+', '/', dirs)
112 file_ext = '.' + type
113 out = open(outfile, 'w')
115 for dir in dirs.split(path_sep):
116 # for each valid directory
117 if not os.path.isdir(dir):
119 # walk down the file hierarchy
120 for root,dirs,files in os.walk(dir, followlinks=True):
121 # prevent inifinite recursion
124 dirname = os.path.join(root, dir)
125 dirname = os.path.realpath(dirname)
126 dirname = os.path.normcase(dirname)
127 if dirname not in visited:
133 if len(file) > 4 and file[-4:] == file_ext:
134 # force the use of / since miktex uses / even under windows
135 print(root.replace('\\', '/') + '/' + file, file=out)