-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_recompile.py
More file actions
97 lines (74 loc) · 3.75 KB
/
main_recompile.py
File metadata and controls
97 lines (74 loc) · 3.75 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
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)
try:
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")
except FileNotFoundError:
out_str = { "srcOrgId": "",
"srcProjectId": "",
"srcEnvId": "",
"trgtOrgId": "",
"trgtProjectId": "",
"trgtEnvId": ""
}
with open("settings.json", "w") as f:
json.dump(out_str, f, indent=4)
print("settings.json file not found. Created a new one with empty values.")
print("Please fill in the values for trgtOrgId, trgtProjectId, trgtEnvId.")
exit(1)
print(" RECOMPILE EVENT SCHEMAS TO MATCH THE UI")
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("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}
# read token from token.auth
#-------------------------------get the target schemas and parameters--------------------
#-------------------------------these already exist, and should not be created--------------------
for event_name, event in src_schemas.items():
event:dict
# convert the event from GET to POST format
original_event_desc = str.strip(event.get("description", ""))
patched_event_desc = event.get("description","") + " "
is_enabled = event.get("isEnabled", True)
if event.get("isRestricted"):
print(f"Skipping restricted event {event_name}.")
continue
# create the body for the POST request
# post the event to the target project
response = rh.patch_event(org_id, project_id, environment_id, event_name, patched_event_desc, is_enabled)
if response:
print(f"added extra space to {event_name}, refreshing the event.")
else:
print(f"Failed to create or update {event_name}. Status code: {response.status_code}, Response: {response.text}")
response = rh.patch_event(org_id, project_id, environment_id, event_name, original_event_desc, is_enabled)
if response:
print(f"removed extra space from {event_name} description.")
else:
print(f"Failed to create or update {event_name}. Status code: {response.status_code}, Response: {response.text}")