-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate_index.py
51 lines (44 loc) · 1.3 KB
/
generate_index.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
import os
import sys
INDEX_TEXT_START = """<!DOCTYPE html>
<html>
<head><title>Index of {folderPath}</title></head>
<body>
<h2>Index of {folderPath}</h2>
<hr>
<ul>
<li>
<a href='../'>../</a>
</li>
"""
INDEX_TEXT_END = """
</ul>
</body>
</html>
"""
def index_folder(path_):
print("Indexing: " + path_ + '/')
# Getting the content of the folder
files = os.listdir(folder_path)
# If Root folder, correcting folder name
root = path_
if path_.startswith('public'):
root = path_.replace('public', 'gitlab-allure-history')
index_text = INDEX_TEXT_START.format(folderPath=root)
for file in sorted(files):
# Avoiding index.html files
if file != 'index.html':
index_text += "\t\t<li>\n\t\t\t<a href='" + file + "'>" \
+ file \
+ "</a>\n\t\t</li>\n"
# Recursive call to continue indexing
# if os.path.isdir(folder_path + '/' + file):
# index_folder(folder_path + '/' + file)
index_text += INDEX_TEXT_END
# Create or override previous index.html
# Save indexed content to file
with open(path_ + '/index.html', "w") as index:
index.write(index_text)
folder_path = sys.argv[1]
# Indexing root directory (Script position)
index_folder(folder_path)