-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinstall.py
More file actions
78 lines (62 loc) · 1.82 KB
/
install.py
File metadata and controls
78 lines (62 loc) · 1.82 KB
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
75
76
77
78
#!/usr/bin/env python3
"""A script to be run as part of forgetools/install_python_webservice.py."""
from os import O_CREAT, O_EXCL, O_WRONLY, chmod, close, open as os_open
from pathlib import Path
from re import sub
from subprocess import check_output
HOME = Path.home()
def set_file_permissions():
try:
chmod(HOME / 'www/python/src/citer.log', 0o660)
except FileNotFoundError:
close(
os_open(
HOME / 'www/python/src/citer.log',
O_CREAT | O_EXCL | O_WRONLY,
0o660,
)
)
chmod(HOME / 'www/python/src/config.py', 0o660)
def write_uwsgi_ini():
(HOME / 'www/python/uwsgi.ini').write_bytes(
(HOME / 'www/python/src/uwsgi.ini').read_bytes()
)
def write_webservice_template():
# https://wikitech.wikimedia.org/wiki/Help:Toolforge/Web#Webservice_templates
(HOME / 'service.template').write_bytes(b'cpu: 3\nmem: 2Gi\n')
def copy_config():
committer_date = (
check_output(
[
'git',
'-C',
f'{HOME}/www/python/src',
'log',
'-1',
'--format=%cd',
'--date=short',
]
)
.rstrip()
.replace(b'-', b'.')
)
def opener(path, flags):
return os_open(path, flags, 0o660)
with open(
HOME / 'www/python/src/config.py', 'wb', opener=opener
) as src_config:
src_config.write(
sub(
b"(USER_AGENT = '.*)'\n",
rb'\1 v' + committer_date + b"'\n",
(HOME / '.citer_config').read_bytes(),
1,
)
)
def main():
copy_config()
write_uwsgi_ini()
write_webservice_template()
set_file_permissions()
if __name__ == '__main__':
main()