2 # This file is part of LyX, the document processor.
3 # Licence details can be found in the file COPYING.
6 # \author Jean-Marc Lasgouttes
7 # \author Jürgen Spitzmüller
10 # Full author contact details are available in file CREDITS.
12 # all files -> without option
13 # TeX class files -> option cls
14 # TeX style files -> option sty
15 # bibtex style files -> option bst
16 # bibtex database files -> option bib
17 # biblatex bibstyles -> option bbx
18 # biblatex citestyles -> option cbx
21 # of kpsewhich and creates a
22 # bstFiles.lst, clsFiles.lst, styFiles.lst, bibFiles.lst,
23 # bbxFiles.lst, cbxFiles.lst
24 # without any parameter all files are created.
26 # Herbert Voss <voss@perce.org>
28 # Updates from Jean-Marc Lasgouttes.
30 # bib, bbx and cbx support added by Juergen Spitzmueller (v0.4)
32 # translated to python by Bo Peng, so that the script only
33 # relies on python and kpsewhich (no shell command is used).
38 cls_stylefile = 'clsFiles.lst'
39 sty_stylefile = 'styFiles.lst'
40 bst_stylefile = 'bstFiles.lst'
41 bib_files = 'bibFiles.lst'
42 bbx_files = 'bbxFiles.lst'
43 cbx_files = 'cbxFiles.lst'
46 '''utility function: run a command and get its output as a string
54 # processing command line options
56 if sys.argv[1] in ['--help', '-help']:
57 print('''Usage: TeXFiles.py [-version | cls | sty | bst | bib | bbx| cbx ]
58 Default is without any Parameters,
59 so that all files will be created''')
64 if type not in ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx']:
65 print('ERROR: unknown type', type)
68 # if no parameter is specified, assume all
69 types = ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx']
72 # MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate
73 # directories in path lists whereas Unix uses `:'. Make an exception for
74 # Cygwin, where we could have either teTeX (using `:') or MikTeX (using `;').
75 # Create a variable that holds the right character to be used by the scripts.
77 if sys.platform == 'cygwin':
78 if ';' in cmdOutput('kpsewhich --show-path=.tex'):
83 # process each file type
85 print("Indexing files of type", type)
87 outfile = cls_stylefile
90 outfile = sty_stylefile
93 outfile = bst_stylefile
105 dirs = cmdOutput('kpsewhich --show-path=' + kpsetype).replace('!!', '').strip()
106 # remove excessive //
107 dirs = re.sub('//+', '/', dirs)
109 file_ext = '.' + type
110 out = open(outfile, 'w')
112 for dir in dirs.split(path_sep):
113 # for each valid directory
114 if not os.path.isdir(dir):
116 # walk down the file hierarchy
117 for root,dirs,files in os.walk(dir, followlinks=True):
118 # prevent inifinite recursion
121 dirname = os.path.join(root, dir)
122 dirname = os.path.realpath(dirname)
123 dirname = os.path.normcase(dirname)
124 if dirname not in visited:
130 if len(file) > 4 and file[-4:] == file_ext:
131 # force the use of / since miktex uses / even under windows
132 print(root.replace('\\', '/') + '/' + file, file=out)