%s | %s | %s | %s | %s"
items = summary_table.items(); items.sort(num_cmp)
for (ch, entries) in items:
for (module, lines, desc) in entries:
totallines += lines
files = link(module+'.py', '.py')
if os.path.exists(module+'.txt'):
files += ' ' + link(module+'.txt', '.txt')
tbl += [fmt % (ch, link(module+'.html', module),
files, lines, desc)]
tbl += [fmt % ('', '', '', totallines, ''), ""]
## Now read the tblfile, and replace the first table with tbl
old = open(tblfile).read()
new = re.sub("(?s)()",
r'\1' + '\n'.join(tbl) + r'\3', old, 1)
open(tblfile, 'w').write(new)
def num_cmp(x, y):
def num(x):
nums = re.findall('[0-9]+', x or '')
if nums: return int(nums[0])
return x
return cmp(num(x[0]), num(y[0]))
### Above is general (more or less); below is specific to my files.
def comment(text): return i(color("green", text))
replacements = [
(r'&', '&'),
(r'<', '<'),
(r'>', '>'),
(r'(?ms)^#+[#_]{10,} *\n', ' '),
(r"""('[^']*?'|"[^"]*?")""", comment(g1)),
(r'(?s)(""".*?"""|' + r"'''.*?''')", comment(g1)),
(r'(#.*)', color("cc33cc", g1)),
(r'(?m)(^[a-zA-Z][a-zA-Z_0-9, ]+)(\s+=\s+)', hilite(g1) + g2),
(r'(?m)(^\s*)(def\s+)(%s)' % id, g1 + b(g2) + hilite(g3)),
(r'(?m)(^\s*)(class\s+)(%s)' % id, g1 + b(g2) + hilite(g3)),
(r'(from\s+)([a-z]+)(\s+import)', importer),
(r'(import\s+)([a-z, ]+)(\s|\n|$|,)', importer),
]
if __name__ == '__main__':
import sys, glob
files = []
for arg in sys.argv[1:]:
files.extend(glob.glob(arg))
convert_files(files)
## ENHANCEMENTS:
## Can get confused with """ and '''; not a problem in practice.
## Maybe we should create an index
## Probably should switch to Doxygen
|
---|