This repository has been archived by the owner on Nov 20, 2021. It is now read-only.
forked from atomcorp/themes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.py
74 lines (61 loc) · 3.04 KB
/
update.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
import requests as r
from termcolor import cprint, colored
from os.path import join
from os import getcwd
from vars import _VERSION
defaultThemesUrl = 'https://raw.githubusercontent.com/atomcorp/themes/master/themes.json'
customThemesUrl = 'https://raw.githubusercontent.com/atomcorp/themes/master/app/src/custom-colour-schemes.json'
wTTUrl = 'https://raw.githubusercontent.com/king-retracted/windowsterminalterminal/master/vars.py'
def writeUpdate(srcUrl):
with open(str(srcUrl).split('/')[-1], 'w') as f:
content = str(r.get(srcUrl).text)
f.write(content)
def returnFileContent(file):
with open(file, 'r') as f:
return f.read()
def checkUpdate():
_locals = locals()
try:
global wTTUpdateContent
global defaultThemesContent
global customThemesContent
wTTUpdateContent = r.get(wTTUrl).text
defaultThemesContent = r.get(defaultThemesUrl).text
customThemesContent = r.get(customThemesUrl).text
except:
cprint('Error occured when fetching for the remote content. Do you have internet?', color='red')
exec(wTTUpdateContent)
cprint('Attempting an update for the project _VERSION...', color='blue')
if _VERSION != _locals['_VERSION']:
cprint('Local version: {} does not match remote version: {}!'.format(_VERSION, _locals['_VERSION']), color='red')
cprint('Attempting an update...', color='yellow')
writeUpdate(wTTUrl)
writeUpdate('https://raw.githubusercontent.com/king-retracted/windowsterminalterminal/master/main.py')
cprint('Updated _VERSION.', color='green')
else:
cprint('Local version matches remote version.', color='green')
cprint('Attempting an update for the project themes.json...', color='blue')
if returnFileContent(join(getcwd(), 'themes.json')) != defaultThemesContent:
cprint('Local themes.json does not match remote themes.json!', color='red')
cprint('Attempting an update...', color='yellow')
writeUpdate(defaultThemesUrl)
cprint('Updated themes.json.', color='green')
else:
cprint('Local version matches remote version.', color='green')
cprint('Attempting an update for custom-colour-schemes.json...', color='blue')
if returnFileContent(join(getcwd(), 'custom-colour-schemes.json')) != customThemesContent:
cprint('Local custom-color-schemes.json does not match remote custom-colour-schemes.json!', color='red')
cprint('Attempting an update...', color='yellow')
writeUpdate(customThemesUrl)
cprint('Updated custom-colour-schemes.json.', color='green')
else:
cprint('Local version matches remote version.', color='green')
def main():
cprint('Would you like to check for updates? (Y/n)\n', color='blue')
if input(colored(' > ', color='yellow')).lower() in ('Y', 'y', '', 'yes'):
checkUpdate()
else:
cprint('Continuing execution...', color='green')
if __name__ == '__main__':
cprint('This code should not be ran independently. Continuing execution...', color='yellow')
main()