-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.py
More file actions
executable file
·63 lines (45 loc) · 1.62 KB
/
configure.py
File metadata and controls
executable file
·63 lines (45 loc) · 1.62 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
#!/usr/bin/env python3
import argparse
import os
from console_helpers import print_green
CONFIG_PY_NAME = 'config.py'
CONFIG_SH_NAME = 'config.sh'
CONFIG_PY_TEXT = """
AISY = '/home/ayrat/projects/aisy/aisy.py'
GOAL = '/home/ayrat/projects/GOAL-20141117/gc'
"""
CONFIG_SH_TEXT = """
IIMC_CHECKER=/home/ayrat/projects/iimc-2.0/iimc
"""
def _get_root_dir() -> str:
return os.path.dirname(os.path.abspath(__file__))
def _user_confirmed(question:str):
answer = input(question + ' [y/n] ').strip()
assert answer in 'yYnN', answer
return answer in 'yY'
def _check_files_exist(files):
existing = list(filter(lambda f: os.path.exists(f), files))
return existing
def main():
config_py = os.path.join(_get_root_dir(), CONFIG_PY_NAME)
config_sh = os.path.join(_get_root_dir(), CONFIG_SH_NAME)
existing = _check_files_exist([CONFIG_PY_NAME, CONFIG_SH_NAME])
if not existing or \
_user_confirmed('{files} already exist(s).\n'.format(files=existing) +
'Replace?'):
with open(config_py, 'w') as file:
file.write(CONFIG_PY_TEXT)
with open(config_sh, 'w') as file:
file.write(CONFIG_SH_TEXT)
print_green('Created {files}.\n'
'Now edit them with your paths.'.
format(files=[CONFIG_PY_NAME, CONFIG_SH_NAME]))
return True
return False
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=
'Generate local configuration file')
args = parser.parse_args()
res = main()
print(['not done', 'done'][res])
exit(res)