-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_compare.py
More file actions
106 lines (80 loc) · 4.35 KB
/
main_compare.py
File metadata and controls
106 lines (80 loc) · 4.35 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
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
import requests
import json
from methods import AnalyticsUIRequestHelper
from methods import recursively_get_parameters, convert_event_from_get_to_post
from methods import check_for_prefix
# step 1 - get the token
# step 2 - get the project IDs (can we convert IDs to names?)
# step 2 - get the environment names
with open("token.auth", "r+") as f:
token = f.read().strip()
rh = AnalyticsUIRequestHelper("https://services.unity.com", token)
with open("settings.json", "r+") as f:
settings = json.load(f)
org_id = settings["srcOrgId"]
project_id = settings["srcProjectId"]
environment_id = settings["srcEnvId"]
target_environment_id = settings["trgtEnvId"]
target_project_id = settings["trgtProjectId"]
target_org_id = settings["trgtOrgId"]
if not project_id or not environment_id:
raise ValueError("Project name and environment name must be set in settings.json")
print(" COMPARISON TOOL")
print("-------------------------------------------------")
print("Here's a link to the source project:")
print(f"https://cloud.unity.com/home/organizations/{org_id}/projects/{project_id}/environments/{environment_id}")
input("If this is correct, press enter to continue... If not, terminate the script and change the settings.json file.")
print("-------------------------------------------------")
print("Here's a link to the comparison project:")
print(f"https://cloud.unity.com/home/organizations/{target_org_id}/projects/{target_project_id}/environments/{target_environment_id}")
input("If this is correct, press enter to continue... If not, terminate the script and change the settings.json file. \n THERE WILL BE NO FURTHER CONFIRMATIONS.")
print("thanks! beginning...")
#------------------------------get the source schemas and parameters--------------------
src_schemas = rh.get_schemas(org_id, project_id, environment_id)
if not src_schemas:
print("No schemas found in source project. This probably means your token is expired. Look in the cookie for https://cloud.unity.com/, under 'token'.")
print("Store the latest token in token.auth and re-run the script.")
print("Exiting...")
exit(1)
schema_names = [x["name"] for x in src_schemas ]
src_schemas = {x["name"]: x for x in src_schemas}
src_params = rh.get_parameters(org_id, project_id, environment_id)
src_params = {x["name"]: x for x in src_params}
# read token from token.auth
#-------------------------------get the target schemas and parameters--------------------
#-------------------------------these already exist, and should not be created--------------------
destination_events = rh.get_schemas(target_org_id, target_project_id, target_environment_id)
destination_events = {x["name"]: x for x in destination_events}
destination_params = rh.get_parameters(target_org_id, target_project_id, target_environment_id)
destination_params = {x["name"]: x for x in destination_params}
# these are parameters that are not in a schema
required_params = {}
print("event schemas:")
for schema_name, schema in src_schemas.items():
# check if it exists in the destination
recursively_get_parameters(schema, required_params)
if schema_name in destination_events:
print(f" {schema_name} (exists in destination)")
elif not check_for_prefix(schema_name):
print(f"? {schema_name} (restricted parameter, cannot be created in destination)")
else:
print(f"X {schema_name} (does not exist in destination)")
for schema_name in destination_events:
# check if it exists in the source
if schema_name not in src_schemas:
print(f"X {schema_name} (exists in destination but not in source)")
print("parameters:")
for param_name in src_params:
# check if it exists in the destination
if param_name in destination_params:
print(f" {param_name} (exists in destination)")
elif not check_for_prefix(param_name):
print(f"? {param_name} (restricted parameter, cannot be created in destination)")
elif param_name in required_params:
print(f"X {param_name} (does not exist in destination, required for an event)")
else:
print(f"? {param_name} (does not exist in destination, not used in any events)")
for param_name in destination_params:
# check if it exists in the source
if param_name not in src_params:
print(f"X {param_name} (exists in destination but not in source)")