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).
40 cls_stylefile = 'clsFiles.lst'
41 sty_stylefile = 'styFiles.lst'
42 bst_stylefile = 'bstFiles.lst'
43 bib_files = 'bibFiles.lst'
44 bbx_files = 'bbxFiles.lst'
45 cbx_files = 'cbxFiles.lst'
48 '''utility function: run a command and get its output as a string
56 # processing command line options
58 if sys.argv[1] in ['--help', '-help']:
59 print '''Usage: TeXFiles.py [-version | cls | sty | bst | bib | bbx| cbx ]
60 Default is without any Parameters,
61 so that all files will be created'''
66 if type not in ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx']:
67 print 'ERROR: unknown type', type
70 # if no parameter is specified, assume all
71 types = ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx']
74 # MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate
75 # directories in path lists whereas Unix uses `:'. Make an exception for
76 # Cygwin, where we could have either teTeX (using `:') or MikTeX (using `;').
77 # Create a variable that holds the right character to be used by the scripts.
79 if sys.platform == 'cygwin':
80 if ';' in cmdOutput('kpsewhich --show-path=.tex'):
85 # process each file type
87 print "Indexing files of type", type
89 outfile = cls_stylefile
92 outfile = sty_stylefile
95 outfile = bst_stylefile
107 dirs = cmdOutput('kpsewhich --show-path=' + kpsetype).replace('!!', '').strip()
108 # remove excessive //
109 dirs = re.sub('//+', '/', dirs)
111 file_ext = '.' + type
112 out = open(outfile, 'w')
113 for dir in dirs.split(path_sep):
114 # for each valid directory
115 if not os.path.isdir(dir):
117 # walk down the file hierarchy
118 for root,path,files in os.walk(dir):
121 if len(file) > 4 and file[-4:] == file_ext:
122 # force the use of / since miktex uses / even under windows
123 print >> out, root.replace('\\', '/') + '/' + file