-
Notifications
You must be signed in to change notification settings - Fork 0
/
newGoModule.py
executable file
·42 lines (39 loc) · 1.2 KB
/
newGoModule.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
#!/usr/bin/env python
from sys import argv, version_info, exit
from os import makedirs
from os.path import isdir, abspath, dirname, join
PY2 = version_info[0] == 2
tpl = """<!DOCTYPE html>
<html>
<head>
<meta title="tcw.im/{name}">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="tcw.im/{name} git https://github.com/staugur/{pkg}">
<meta http-equiv="refresh" content="0; url=https://pkg.go.dev/tcw.im/{name}">
</head>
<body>
Redirecting to docs at <a href="https://pkg.go.dev/tcw.im/{name}">pkg.go.dev/tcw.im/{name}</a>...
</body>
</html>
"""
if __name__ == "__main__":
try:
name = argv[1]
except IndexError:
print("usage: {} go-module-name github-repo-name".format(argv[0]))
exit(1)
try:
pkg = argv[2]
except IndexError:
pkg = name
pub = join(dirname(abspath(__file__)), "static", name)
print(tpl.format(name=name, pkg=pkg))
try:
raw_input() if PY2 else input()
except KeyboardInterrupt:
pass
else:
if not isdir(pub):
makedirs(pub)
with open(join(pub, "index.html"), "w") as fp:
fp.write(tpl.format(name=name, pkg=pkg))