-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathindex_gen.py
executable file
·66 lines (56 loc) · 1.91 KB
/
index_gen.py
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
#!/usr/bin/env python
#
# index_gen.py
# Laszlo Szathmary, 2011 (jabba.laci@gmail.com)
#
# Project's home page:
# https://pythonadventures.wordpress.com/2011/03/26/static-html-filelist-generator/
#
# Version: 0.1
# Date: 2011-03-26 (yyyy-mm-dd)
#
# This free software is copyleft licensed under the same terms as Python, or,
# at your option, under version 2 of the GPL license.
#
import os
import os.path
import sys
class SimpleHtmlFilelistGenerator:
# start from this directory
base_dir = None
def __init__(self, dir):
self.base_dir = dir
def print_html_header(self):
print """<html>
<body>
<code>
""",
def print_html_footer(self):
#home = 'https://pythonadventures.wordpress.com/2011/03/26/static-html-filelist-generator/'
#name = 'Static HTML Filelist Generator'
print '</code>'
#href = "<a href=\"%s\">%s</a>" % (home, name)
#print "<p><i><sub>This page was generated with Jabba Laci's %s.</sub></p>" % href
print """</body>
</html>
""",
def processDirectory ( self, args, dirname, filenames ):
print '<strong>', dirname + '/', '</strong>', '<br>'
for filename in sorted(filenames):
rel_path = os.path.join(dirname, filename)
if rel_path in [sys.argv[0], './index.html']:
continue # exclude this generator script and the generated index.html
if os.path.isfile(rel_path):
href = "<a href=\"%s\">%s</a>" % (rel_path, filename)
print ' ' * 4, href, '<br>'
def start(self):
self.print_html_header()
os.path.walk( self.base_dir, self.processDirectory, None )
self.print_html_footer()
# class SimpleHtmlFilelistGenerator
if __name__ == "__main__":
base_dir = '.'
if len(sys.argv) > 1:
base_dir = sys.argv[1]
gen = SimpleHtmlFilelistGenerator(base_dir)
gen.start()