Skip to content

Commit a7bd536

Browse files
authored
Merge pull request #1892 from KomodoPlatform/whitelabel-utils
Add utils for whitelabel deployments
2 parents a5961d3 + 3d375f1 commit a7bd536

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python3
2+
import json
3+
import requests
4+
5+
'''
6+
Purpose: Scans the light and dark theme json files for a list of whitelabel
7+
branches, and compares them with the dev branch to identify theme
8+
selectors which are obsolete or not present in the whitelabel branch.
9+
10+
Usage: `./compare_themes.py`
11+
'''
12+
13+
REPO_URL = "https://raw.githubusercontent.com/KomodoPlatform/atomicDEX-Desktop"
14+
BRANCHES = ['smartdex', 'GleecDEX', 'shibadex']
15+
16+
17+
def get_theme_url(branch, theme):
18+
'''Returns a github url for a branch theme.'''
19+
path = f"assets/themes/Default%20-%20{theme.title()}"
20+
return f"{REPO_URL}/{branch}/{path}/colors.json"
21+
22+
23+
def get_themes_data(branches):
24+
'''Returns a dict of dark/light theme data for each branch.'''
25+
themes = {}
26+
for branch in branches+['dev']:
27+
themes.update({branch: {}})
28+
for theme in ['light', 'dark']:
29+
url = get_theme_url(branch, theme)
30+
themes[branch].update({
31+
theme: requests.get(url).json()
32+
})
33+
return themes
34+
35+
36+
def get_selectors(themes, branch='dev'):
37+
'''Returns a list of selectors within each theme for a branch.'''
38+
return {
39+
'light': set(themes[branch]['light'].keys()),
40+
'dark': set(themes[branch]['dark'].keys())
41+
}
42+
43+
44+
def compare_branch_themes(branches, show_results=True):
45+
'''Scans whitelabel theme data to identify missing/obsolete selectors.'''
46+
themes = get_themes_data(branches)
47+
dev_selectors = get_selectors(themes, 'dev')
48+
49+
for branch in branches:
50+
for theme in ['light', 'dark']:
51+
selectors = set(themes[branch][theme].keys())
52+
missing = dev_selectors[theme].difference(selectors)
53+
themes[branch].update({
54+
f"missing_{theme}": missing,
55+
f"obsolete_{theme}": selectors.difference(dev_selectors[theme])
56+
})
57+
if show_results:
58+
output_results(themes, branch, theme)
59+
60+
61+
def output_results(themes, branch, theme):
62+
'''Outputs results for a branch to the console.'''
63+
print(f"\n#### {branch} {theme} ####")
64+
if len(themes[branch][f"obsolete_{theme}"]) == 0:
65+
print(f"No obsolete selectors")
66+
else:
67+
for i in themes[branch][f"obsolete_{theme}"]:
68+
print(f"Obsolete selector: {i}...")
69+
70+
if len(themes[branch][f"missing_{theme}"]) == 0:
71+
print(f"No obsolete selectors")
72+
else:
73+
for i in themes[branch][f"missing_{theme}"]:
74+
dev_color = themes['dev'][theme][i]
75+
for j in themes['dev'][theme]:
76+
if dev_color == themes['dev'][theme][j]:
77+
if j in themes[branch][theme]:
78+
print(f"Missing {i}... Try {themes[branch][theme][j]}")
79+
break
80+
81+
82+
if __name__ == '__main__':
83+
compare_branch_themes(BRANCHES, True)

0 commit comments

Comments
 (0)