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
21 # of kpsewhich and creates a
22 # bstFiles.lst, clsFiles.lst, styFiles.lst, bibFiles.lst
23 # without any parameter all files are created.
25 # Herbert Voss <voss@perce.org>
27 # Updates from Jean-Marc Lasgouttes.
29 # bib support added by Juergen Spitzmueller (v0.3)
31 # translated to python by Bo Peng, so that the script only
32 # relies on python and kpsewhich (no shell command is used).
37 cls_stylefile = 'clsFiles.lst'
38 sty_stylefile = 'styFiles.lst'
39 bst_stylefile = 'bstFiles.lst'
40 bib_files = 'bibFiles.lst'
43 '''utility function: run a command and get its output as a string
51 # processing command line options
53 if sys.argv[1] in ['--help', '-help']:
54 print '''Usage: TeXFiles.py [-version | cls | sty | bst | bib ]
55 Default is without any Parameters,
56 so that all files will be created'''
61 if type not in ['cls', 'sty', 'bst', 'bib']:
62 print 'ERROR: unknown type', type
65 # if no parameter is specified, assume all
66 types = ['cls', 'sty', 'bst', 'bib']
69 # MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate
70 # directories in path lists whereas Unix uses `:'. Make an exception for
71 # Cygwin, where we could have either teTeX (using `:') or MikTeX (using `;').
72 # Create a variable that holds the right character to be used by the scripts.
74 if sys.platform == 'cygwin':
75 if ';' in cmdOutput('kpsewhich --show-path=.tex'):
80 # process each file type
82 print "Indexing files of type", type
84 outfile = cls_stylefile
87 outfile = sty_stylefile
90 outfile = bst_stylefile
96 dirs = cmdOutput('kpsewhich --show-path=' + kpsetype).replace('!!', '').strip()
98 dirs = re.sub('//+', '/', dirs)
100 file_ext = '.' + type
101 out = open(outfile, 'w')
102 for dir in dirs.split(path_sep):
103 # for each valid directory
104 if not os.path.isdir(dir):
106 # walk down the file hierarchy
107 for root,path,files in os.walk(dir):
110 if len(file) > 4 and file[-4:] == file_ext:
111 # force the use of / since miktex uses / even under windows
112 print >> out, root.replace('\\', '/') + '/' + file