32 __cfp_json_path__ =
"/../cFp.json"
33 __env_file_name__ =
"/this_machine_env.sh"
34 __to_be_defined_key__ =
'to-be-defined'
35 __lignin_key__ =
'lignin-conf'
36 __cfenv_small_name__ =
'cfenv-small'
37 __cfenv_path_from_root__ =
'/env/' + __cfenv_small_name__ +
'/'
38 __cfenv_req_packages__ =
'docopt==0.6.2 requests==2.26.0'
40 __mandatory_keys__ = [
'cFpMOD',
'usedRoleDir',
'usedRoleDir2',
'cFpSRAtype',
'roleName1',
'roleName2']
41 __optional_keys__ = [
'cFa',
'additional_lines', __lignin_key__]
44 __replace_regex__ = []
46 __match_regex__.append(
"##ROOTDIR##")
47 __replace_regex__.append(
"abs_path")
49 __match_regex__.append(
"##MOD##")
50 __replace_regex__.append(
"cFpMOD")
52 __match_regex__.append(
"##SRA##")
53 __replace_regex__.append(
"cFpSRAtype")
55 __match_regex__.append(
"##DIR1##")
56 __replace_regex__.append(
"usedRoleDir")
58 __match_regex__.append(
"##DIR2##")
59 __replace_regex__.append(
"usedRoleDir2")
61 __match_regex__.append(
"##ROLE1##")
62 __replace_regex__.append(
"roleName1")
64 __match_regex__.append(
"##ROLE2##")
65 __replace_regex__.append(
"roleName2")
67 __match_regex__.append(
"##virtual_path##")
68 __replace_regex__.append(
"cfenvPath")
70 __match_regex__.append(
"##python3_bin##")
71 __replace_regex__.append(
"sysPython3Bin")
75 me_abs = os.path.realpath(__file__)
76 cfp_json_file = os.path.abspath(me_abs + __cfp_json_path__)
77 print(
"The project describing file {} is invalid.\n{}\n".format(cfp_json_file, msg) +
78 "Please use 'cFBuild update' to fix this project setup.")
86 if 'cFsysPy3_cmd_hint_0' in os.environ
and os.path.isfile(os.environ[
'cFsysPy3_cmd_hint_0']):
87 sys_py_bin = os.environ[
'cFsysPy3_cmd_hint_0']
88 elif 'cFsysPy3_cmd_hint_1' in os.environ
and os.path.isfile(os.environ[
'cFsysPy3_cmd_hint_1']):
89 sys_py_bin = os.environ[
'cFsysPy3_cmd_hint_1']
90 elif os.path.isfile(
'/usr/bin/python3.8'):
91 sys_py_bin =
'/usr/bin/python3.8'
92 elif os.path.isfile(
'/usr/bin/python3'):
93 sys_py_bin =
'/usr/bin/python3'
97 sys_py_bin = os.popen(
'which python3').read()
102 me_abs = os.path.dirname(os.path.realpath(__file__))
103 cfp_json_file = me_abs + __cfp_json_path__
104 with open(cfp_json_file,
'r')
as json_file:
105 data = json.load(json_file)
107 root_abs = os.path.realpath(me_abs+
"/../")
108 data[
'abs_path'] = root_abs
112 cfenv_dir = os.path.abspath(root_abs + __cfenv_path_from_root__)
113 if not os.path.isdir(cfenv_dir)
or not os.path.isfile(
"{}/bin/activate".format(cfenv_dir)):
115 os.system(
"rm -rf {}".format(cfenv_dir))
117 print(
"[INFO] the python virutalenv for this project on this machine is missing, installing it...")
118 os.system(
'cd {}; virtualenv -p {} {}'
119 .format(os.path.abspath(cfenv_dir +
'/../'), sys_py_bin, __cfenv_small_name__))
120 os.system(
'/bin/bash -c "source {}/bin/activate; pip install {}"'.format(cfenv_dir, __cfenv_req_packages__))
122 data[
'cfenvPath'] = cfenv_dir
123 data[
'sysPython3Bin'] = sys_py_bin
125 for e
in __mandatory_keys__:
126 if e
not in data.keys():
129 env_file = me_abs + __env_file_name__
132 if os.path.exists(env_file):
133 json_time = os.path.getmtime(cfp_json_file)
134 env_time = os.path.getmtime(env_file)
136 if env_time >= json_time:
140 with open(me_abs +
"/machine_env.template",
"r")
as input, open(env_file,
"w+")
as outfile:
142 for i
in range(0, len(__match_regex__)):
143 out = re.sub(re.escape(__match_regex__[i]), data[__replace_regex__[i]], out)
145 if 'additional_lines' in data.keys():
147 for e
in data[
'additional_lines']:
148 new_line =
str(e) +
'\n'
154 os.system(
"chmod +x {}".format(env_file))
157 if __name__ ==
'__main__':
def print_incomplete(msg="")