forked from szafranski/RH-ota
-
Notifications
You must be signed in to change notification settings - Fork 3
/
compatibility_check.py
executable file
·63 lines (49 loc) · 1.91 KB
/
compatibility_check.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
import os
import platform
from pathlib import Path
import json
# removes old aliases, especially doubled ones and bad leftovers from ~/.bashrc file
def aliases_clean(start, end, file_name, *words):
if platform.system() == "Linux":
write_lines = []
skipping = False
with open(file_name, 'r') as read_obj:
for line in read_obj:
if start in line:
skipping = True
if not skipping:
write_lines.append(line)
if end in line:
skipping = False
for word in words:
if word in line:
write_lines.remove(line)
with open(file_name, 'w') as write_obj:
write_obj.write("".join(write_lines))
return False
def virtual_env_check(file_path, word):
with open(file_path, 'r') as file:
content = file.read()
if word in content:
print('virtual env in .bashrc already setup')
else:
os.system("echo 'VIRTUAL_ENV_DISABLE_PROMPT=1' >> ~/.bashrc")
os.system("echo 'source ~/.venv/bin/activate' >> ~/.bashrc")
def json_user_change(home_dir):
config_file = f"{home_dir}/RH_Install-Manager/updater-config.json"
if os.path.exists(config_file):
with open(config_file, 'r') as file:
data = json.load(file)
if 'pi_user' in data:
pi_user_value = data['pi_user']
data['user'] = pi_user_value
with open(config_file, 'w') as file:
json.dump(data, file, indent=2)
def main():
home_dir = str(Path.home())
Path(f"{home_dir}/.rhim_markers").mkdir(exist_ok=True)
aliases_clean('Shortcut', 'After', f'{home_dir}/.bashrc', 'uu', 'updateupdater', '# #')
virtual_env_check(f'{home_dir}/.bashrc', 'VIRTUAL_ENV_DISABLE_PROMPT')
json_user_change(home_dir)
if __name__ == "__main__":
main()