-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_html.py
executable file
·74 lines (61 loc) · 2.05 KB
/
make_html.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
67
68
69
70
71
72
73
74
#!/usr/local/bin/python
import os
import sys
HEADER = '''
<style>
img {
width: 256px;
height: auto
}
</style>
'''
line_svg_dirname = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'line_svgs')
def generate_duplicates_file():
line_svg_htmlname = 'duplicates.html'
dirs = os.listdir(line_svg_dirname)
html_path = '{}/{}'.format(line_svg_dirname, line_svg_htmlname)
html_fd = open(html_path, 'w')
html_fd.write(HEADER)
set_of_all = None
for dirname in dirs:
dirpath = os.path.join(line_svg_dirname, dirname)
if os.path.isdir(dirpath):
files = set(os.listdir(dirpath))
if not set_of_all:
set_of_all = files
else:
set_of_all = set_of_all.intersection(files)
for dup in set_of_all:
for dirname in dirs:
dirpath = os.path.join(line_svg_dirname, dirname)
if os.path.isdir(dirpath):
html_fd.write('<img src="{}/{}" />'.format(dirpath, dup))
html_fd.write("<br>\n")
html_fd.close()
def generate_index_files(forDir=None):
dirs = os.listdir(line_svg_dirname)
for dirname in dirs:
if forDir and dirname != forDir:
continue
dirpath = os.path.join(line_svg_dirname, dirname)
if os.path.isdir(dirpath):
html_path = '{}/{}.html'.format(line_svg_dirname, dirname)
html_fd = open(html_path, 'w')
html_fd.write(HEADER)
for filename in sorted(os.listdir(dirpath)):
html_fd.write('<img src="{}/{}" />'.format(dirpath, filename))
html_fd.close()
print 'generated index file {}'.format(html_path)
def print_usage():
print 'usage: ./make_html.py <index|dups>'
exit()
if __name__ == '__main__':
if len(sys.argv) == 1:
print_usage()
if sys.argv[1] == 'index':
dirname = sys.argv[2] if len(sys.argv) == 3 else None
generate_index_files(forDir=dirname)
elif sys.argv[1] == 'dups':
generate_duplicates_file()
else:
print_usage()