-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_utils.py
111 lines (89 loc) · 3.28 KB
/
app_utils.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
import shutil
import json
from os import path
current_directory = os.getcwd().replace("/apkExplore", "")
config_file_name = current_directory + "/output/config.json"
def sync_front_end_data():
src_path = current_directory + '/output'
dst_path = current_directory + '/frontend/src/data'
if os.path.exists(dst_path):
shutil.rmtree(dst_path)
shutil.copytree(src_path, dst_path)
def create_config_front_end_file():
json_initial_data = {
"configs": []
}
json_object = json.dumps({}, indent=4)
with open(config_file_name, "w") as outfile:
outfile.write(json_object)
def get_list_of_configs():
list_configs = []
if path.isfile(config_file_name) is False:
create_config_front_end_file()
with open(config_file_name) as fp:
data = json.load(fp)
if "configs" in data:
list_configs = data["configs"]
return list_configs
def write_config_file(list_configs):
with open(config_file_name, 'w') as json_file:
json.dump({
"configs": list_configs
}, json_file,
indent=4,
separators=(',', ': '))
def add_new_config(app_name, device, mode):
new_config = {
"config": {
"isLoading": "yes",
"isDone": "no",
"appName": app_name,
"device": device,
"mode": mode,
"activities": [],
"nodes": [],
"edges": []
}
}
list_configs = get_list_of_configs()
is_new_config = True
for config in list_configs:
current_config = config["config"]
if current_config["appName"] == app_name and current_config["device"] == device and current_config[
"mode"] == mode:
is_new_config = False
break
if is_new_config:
list_configs.append(new_config)
write_config_file(list_configs)
def add_new_activity_to_config(app_name, device, mode, activity_name):
list_configs = get_list_of_configs()
for config in list_configs:
current_config = config["config"]
print(current_config)
if current_config["appName"] == app_name and current_config["device"] == device and current_config[
"mode"] == mode:
current_config["activities"].append(activity_name)
write_config_file(list_configs)
def add_new_node_to_config(app_name, device, mode, node):
add_new_config(app_name,device,mode)
list_configs = get_list_of_configs()
for config in list_configs:
current_config = config["config"]
if current_config["appName"] == app_name and current_config["device"] == device and current_config[
"mode"] == mode:
current_config["nodes"].append(node.nodeActivityName)
write_config_file(list_configs)
def add_new_edge_to_config(app_name, device, mode, edge):
add_new_config(app_name,device,mode)
list_configs = get_list_of_configs()
for config in list_configs:
current_config = config["config"]
if current_config["appName"] == app_name and current_config["device"] == device and current_config[
"mode"] == mode:
current_config["edges"].append({
"source": edge.src,
"destination": edge.dest
})
write_config_file(list_configs)