2006-08-08 10:42:59 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-06-27 02:39:03 +00:00
|
|
|
|
|
|
|
# file TeXFiles.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
2006-08-08 10:42:59 +00:00
|
|
|
# \author Herbert Voß
|
2006-06-27 02:39:03 +00:00
|
|
|
# \author Jean-Marc Lasgouttes
|
2006-08-08 10:42:59 +00:00
|
|
|
# \author Jürgen Spitzmüller
|
2006-06-27 02:39:03 +00:00
|
|
|
# \author Bo Peng
|
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS.
|
|
|
|
|
|
|
|
# all files -> without option
|
|
|
|
# TeX class files -> option cls
|
|
|
|
# TeX style files -> option sty
|
|
|
|
# bibtex style files -> option bst
|
|
|
|
# bibtex database files -> option bib
|
2016-12-31 18:45:25 +00:00
|
|
|
# biblatex bibstyles -> option bbx
|
|
|
|
# biblatex citestyles -> option cbx
|
2006-06-27 02:39:03 +00:00
|
|
|
#
|
|
|
|
# with the help
|
|
|
|
# of kpsewhich and creates a
|
2016-12-31 18:45:25 +00:00
|
|
|
# bstFiles.lst, clsFiles.lst, styFiles.lst, bibFiles.lst,
|
|
|
|
# bbxFiles.lst, cbxFiles.lst
|
2006-06-27 02:39:03 +00:00
|
|
|
# without any parameter all files are created.
|
|
|
|
#
|
|
|
|
# Herbert Voss <voss@perce.org>
|
|
|
|
#
|
|
|
|
# Updates from Jean-Marc Lasgouttes.
|
|
|
|
#
|
2016-12-31 18:45:25 +00:00
|
|
|
# bib, bbx and cbx support added by Juergen Spitzmueller (v0.4)
|
2006-06-27 02:39:03 +00:00
|
|
|
#
|
|
|
|
# translated to python by Bo Peng, so that the script only
|
|
|
|
# relies on python and kpsewhich (no shell command is used).
|
|
|
|
#
|
|
|
|
|
|
|
|
import os, sys, re
|
|
|
|
|
|
|
|
cls_stylefile = 'clsFiles.lst'
|
|
|
|
sty_stylefile = 'styFiles.lst'
|
|
|
|
bst_stylefile = 'bstFiles.lst'
|
|
|
|
bib_files = 'bibFiles.lst'
|
2016-12-31 18:45:25 +00:00
|
|
|
bbx_files = 'bbxFiles.lst'
|
|
|
|
cbx_files = 'cbxFiles.lst'
|
2006-06-27 02:39:03 +00:00
|
|
|
|
|
|
|
def cmdOutput(cmd):
|
2006-06-27 21:08:54 +00:00
|
|
|
'''utility function: run a command and get its output as a string
|
|
|
|
cmd: command to run
|
|
|
|
'''
|
|
|
|
fout = os.popen(cmd)
|
|
|
|
output = fout.read()
|
|
|
|
fout.close()
|
|
|
|
return output
|
2006-06-27 02:39:03 +00:00
|
|
|
|
|
|
|
# processing command line options
|
|
|
|
if len(sys.argv) > 1:
|
2006-06-27 21:08:54 +00:00
|
|
|
if sys.argv[1] in ['--help', '-help']:
|
2016-12-31 18:45:25 +00:00
|
|
|
print '''Usage: TeXFiles.py [-version | cls | sty | bst | bib | bbx| cbx ]
|
2006-06-27 21:08:54 +00:00
|
|
|
Default is without any Parameters,
|
|
|
|
so that all files will be created'''
|
2008-04-15 14:04:40 +00:00
|
|
|
sys.exit(0)
|
2006-06-27 21:08:54 +00:00
|
|
|
else:
|
|
|
|
types = sys.argv[1:]
|
|
|
|
for type in types:
|
2016-12-31 18:45:25 +00:00
|
|
|
if type not in ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx']:
|
2006-06-27 21:08:54 +00:00
|
|
|
print 'ERROR: unknown type', type
|
|
|
|
sys.exit(1)
|
2006-06-27 02:39:03 +00:00
|
|
|
else:
|
2006-06-27 21:08:54 +00:00
|
|
|
# if no parameter is specified, assume all
|
2016-12-31 18:45:25 +00:00
|
|
|
types = ['cls', 'sty', 'bst', 'bib', 'bbx', 'cbx']
|
2006-06-27 02:39:03 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate
|
|
|
|
# directories in path lists whereas Unix uses `:'. Make an exception for
|
|
|
|
# Cygwin, where we could have either teTeX (using `:') or MikTeX (using `;').
|
|
|
|
# Create a variable that holds the right character to be used by the scripts.
|
|
|
|
path_sep = os.pathsep
|
|
|
|
if sys.platform == 'cygwin':
|
2011-05-08 21:09:38 +00:00
|
|
|
if ';' in cmdOutput('kpsewhich --show-path=.tex'):
|
2006-06-27 21:08:54 +00:00
|
|
|
path_sep = ';'
|
|
|
|
else:
|
|
|
|
path_sep = ':'
|
2006-06-27 02:39:03 +00:00
|
|
|
|
|
|
|
# process each file type
|
|
|
|
for type in types:
|
2006-06-27 21:08:54 +00:00
|
|
|
print "Indexing files of type", type
|
|
|
|
if type == 'cls':
|
|
|
|
outfile = cls_stylefile
|
|
|
|
kpsetype = '.tex'
|
|
|
|
elif type == 'sty':
|
|
|
|
outfile = sty_stylefile
|
|
|
|
kpsetype = '.tex'
|
|
|
|
elif type == 'bst':
|
|
|
|
outfile = bst_stylefile
|
|
|
|
kpsetype = '.bst'
|
|
|
|
elif type == 'bib':
|
|
|
|
outfile = bib_files
|
|
|
|
kpsetype = '.bib'
|
2016-12-31 18:45:25 +00:00
|
|
|
elif type == 'bbx':
|
|
|
|
outfile = bbx_files
|
|
|
|
kpsetype = '.tex'
|
|
|
|
elif type == 'cbx':
|
|
|
|
outfile = cbx_files
|
|
|
|
kpsetype = '.tex'
|
2006-06-27 02:39:03 +00:00
|
|
|
|
2006-06-27 21:08:54 +00:00
|
|
|
dirs = cmdOutput('kpsewhich --show-path=' + kpsetype).replace('!!', '').strip()
|
|
|
|
# remove excessive //
|
|
|
|
dirs = re.sub('//+', '/', dirs)
|
|
|
|
|
|
|
|
file_ext = '.' + type
|
|
|
|
out = open(outfile, 'w')
|
|
|
|
for dir in dirs.split(path_sep):
|
|
|
|
# for each valid directory
|
|
|
|
if not os.path.isdir(dir):
|
|
|
|
continue
|
|
|
|
# walk down the file hierarchy
|
|
|
|
for root,path,files in os.walk(dir):
|
|
|
|
# check file type
|
|
|
|
for file in files:
|
|
|
|
if len(file) > 4 and file[-4:] == file_ext:
|
|
|
|
# force the use of / since miktex uses / even under windows
|
|
|
|
print >> out, root.replace('\\', '/') + '/' + file
|
|
|
|
out.close()
|
2006-06-27 02:39:03 +00:00
|
|
|
|