-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileList.py
More file actions
135 lines (117 loc) · 4.02 KB
/
FileList.py
File metadata and controls
135 lines (117 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
"""FileList.py
A quick, hacky script to contruct a file list from a set of Python files.
"""
import os, sys
from glob import glob
class FileList(object):
"""Builds a file list for a package of Python modules."""
def __init__(self, name='Webware'):
self._name = name
self._files = []
self._verbose = False
self._filesToIgnore = []
def addFilesToIgnore(self, list):
self._filesToIgnore.extend(list)
def readFiles(self, filename):
filenames = glob(filename)
for name in filenames:
self.readFile(name)
def readFile(self, name):
if name in self._filesToIgnore:
if self._verbose:
print 'Skipping %s...' % name
return
if self._verbose:
print 'Reading %s...' % name
self._files.append(name)
def printList(self, file=sys.stdout):
if isinstance(file, basestring):
file = open(file, 'w')
closeFile = True
else:
closeFile = False
name = self._name
title = 'File List of %s' % name
file.write('%s\n%s\n\n' % (title, '='*len(title)))
for filename in sorted(self._files, key=lambda f: f.lower()):
file.write(filename + '\n')
file.write('\n')
if closeFile:
file.close()
def printForWeb(self, file=sys.stdout):
if isinstance(file, basestring):
file = open(file, 'w')
closeFile = True
else:
closeFile = False
name = self._name
title = 'File List of %s' % name
other = ('<a href="ClassList.html">alphabetical class list<a>'
' and <a href="ClassHierarchy.html">class hierarchy</a>'
' of %s' % name)
file.write('''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<title>%s</title>
<style type="text/css">
<!--
body { background: #FFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
padding: 6pt; }
th { background-color: #CCF; text-align: left; }
td { background-color: #EEF; }
.center { text-align: center; }
.center table { margin-left: auto; margin-right: auto; text-align: left; }
-->
</style>
</head>
<body><div class="center">
<h1>%s</h1>
<p>See also the %s.</p>
<table cellpadding="2" cellspacing="2">
''' % (title, title, other))
file.write('<tr><th>Source File</th>'
'<th>Source</th><th>Doc</th><th>Summary</th></tr>\n')
for filename in sorted(self._files, key=lambda f: f.lower()):
file.write('<tr><td>%s</td></tr>\n' % self.links(filename))
file.write('''</table>
</div></body>
</html>''')
if closeFile:
file.close()
def links(self, filename):
"""In support of printForWeb()"""
name = self._name
links = []
# souce file
if os.path.exists(filename):
links.append('<a href="../../%s">%s</a>' % (filename, filename))
else:
links.append(' ')
filename = os.path.basename(filename)
module = os.path.splitext(filename)[0]
# highlighted source file
if os.path.exists('Docs/Source/Files/%s.html' % module):
links.append('<a href="Files/%s.html">source</a>' % module)
else:
links.append(' ')
# doc file
if os.path.exists('Docs/Source/Docs/%s.%s.html' % (name, module)):
links.append('<a href="Docs/%s.%s.html">doc</a>' % (name, module))
else:
links.append(' ')
# summary file
if os.path.exists('Docs/Source/Summaries/%s.html' % module):
links.append('<a href="Summaries/%s.html">summary</a>' % module)
else:
links.append(' ')
# finish up
return '</td><td class="center">'.join(links)
def main(args):
filelist = FileList()
for filename in args:
filelist.readFiles(filename)
filelist.printList()
if __name__ == '__main__':
main(sys.argv[1:])