2 # -*- coding: utf-8 -*-
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
9 # \author Jean-Marc Lasgouttes
10 # \author Jürgen Spitzmüller
13 # Full author contact details are available in file CREDITS.
15 # all files -> without option
16 # TeX class files -> option cls
17 # TeX style files -> option sty
18 # bibtex style files -> option bst
19 # bibtex database files -> option bib
22 # of kpsewhich and creates a
23 # bstFiles.lst, clsFiles.lst, styFiles.lst, bibFiles.lst
24 # without any parameter all files are created.
26 # Herbert Voss <voss@perce.org>
28 # Updates from Jean-Marc Lasgouttes.
30 # bib support added by Juergen Spitzmueller (v0.3)
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'
44 '''utility function: run a command and get its output as a string
52 # processing command line options
54 if sys.argv[1] in ['--help', '-help']:
55 print '''Usage: TeXFiles.py [-version | cls | sty | bst | bib ]
56 Default is without any Parameters,
57 so that all files will be created'''
62 if type not in ['cls', 'sty', 'bst', 'bib']:
63 print 'ERROR: unknown type', type
66 # if no parameter is specified, assume all
67 types = ['cls', 'sty', 'bst', 'bib']
70 # MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate
71 # directories in path lists whereas Unix uses `:'. Make an exception for
72 # Cygwin, where we could have either teTeX (using `:') or MikTeX (using `;').
73 # Create a variable that holds the right character to be used by the scripts.
75 if sys.platform == 'cygwin':
76 # MikTeX's kpsewhich says "kpathsea emulation version x.x.x", whereas
77 # teTeX's simply "kpathsea version x.x.x".
78 if 'emulation' in cmdOutput('kpsewhich --version'):
83 # process each file type
85 print "Indexing files of type", type
87 outfile = cls_stylefile
90 outfile = sty_stylefile
93 outfile = bst_stylefile
99 dirs = cmdOutput('kpsewhich --show-path=' + kpsetype).replace('!!', '').strip()
100 # remove excessive //
101 dirs = re.sub('//+', '/', dirs)
103 file_ext = '.' + type
104 out = open(outfile, 'w')
105 for dir in dirs.split(path_sep):
106 # for each valid directory
107 if not os.path.isdir(dir):
109 # walk down the file hierarchy
110 for root,path,files in os.walk(dir):
113 if len(file) > 4 and file[-4:] == file_ext:
114 # force the use of / since miktex uses / even under windows
115 print >> out, root.replace('\\', '/') + '/' + file