-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure.py
executable file
·70 lines (51 loc) · 1.76 KB
/
configure.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import argparse
import os
import stat
CONFIG_PY_NAME = 'config.py'
CONFIG_SH_NAME = 'setup.sh'
CONFIG_PY_TEXT = """
SPEC_FRAMEWORK_DIR="/home/ayrat/projects/spec-framework/"
"""
CONFIG_SH_TEXT = """
#!/bin/bash
# to run
# . ./setup.sh
# yes, with .
export LD_LIBRARY_PATH=/home/ayrat/projects/pycudd2.0.2/cudd-2.4.2/lib
"""
def _get_root_dir():
return os.path.dirname(os.path.abspath(__file__))
def _user_confirmed(question):
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)
# make 'sh' config executable
os.chmod(config_sh,
os.stat(config_sh).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
print('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)