63
63
64
64
signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(0))
65
65
66
+ def write_index(path, message):
67
+ with open(path, 'wb') as f:
68
+ f.write('\n'.join([
69
+ '<!doctype html>',
70
+ '<html lang="en">',
71
+ '<head>',
72
+ ' <meta charset="utf-8">',
73
+ '</head>',
74
+ '<body>',
75
+ ' {}'.format(message),
76
+ '</body>',
77
+ '</html>',
78
+ '',
79
+ ]).encode('utf-8'))
80
+
66
81
# Launch multiple listeners as threads
67
82
class Thread(threading.Thread):
68
83
def __init__(self, i, socket):
93
108
os.mkdir(arch)
94
109
for operating_system in ['linux']:
95
110
os.mkdir(os.path.join(arch, operating_system))
111
+ content = ['<a href="oc-license">license</a>']
96
112
os.symlink('/usr/share/openshift/LICENSE', 'oc-license')
97
113
98
114
for arch, operating_system, path in [
@@ -112,6 +128,23 @@ spec:
112
128
tar.add(path, basename)
113
129
with zipfile.ZipFile('{}.zip'.format(archive_path_root), 'w') as zip:
114
130
zip.write(path, basename)
131
+ content.append('<a href="{0}">oc ({1} {2})</a> (<a href="{0}.tar">tar</a> <a href="{0}.zip">zip</a>)'.format(target_path, arch, operating_system))
132
+
133
+ for root, directories, filenames in os.walk(temp_dir):
134
+ root_link = os.path.relpath(temp_dir, os.path.join(root, 'child')).replace(os.path.sep, '/')
135
+ for directory in directories:
136
+ write_index(
137
+ path=os.path.join(root, directory, 'index.html'),
138
+ message='<p>Directory listings are disabled. See <a href="">here</a> for available content.</p>'.format(root_link),
139
+ )
140
+ write_index(
141
+ path=os.path.join(root, 'index.html'),
142
+ message='\n'.join(
143
+ ['<ul>'] +
144
+ [' <li>{}</li>'.format(entry) for entry in content] +
145
+ ['</ul>']
146
+ ),
147
+ )
115
148
116
149
# Create socket
117
150
# IPv6 should handle IPv4 passively so long as it is not bound to a
0 commit comments