-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathupdater.py
54 lines (47 loc) · 1.69 KB
/
updater.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
import json
import hashlib
import os
import settingsManager
import threading
import sys
import urllib
import glob
import shutil
import zipfile
def recursive_overwrite(_src, _dest, _ignore=None):
if os.path.isdir(_src):
if not os.path.isdir(_dest):
os.makedirs(_dest)
files = os.listdir(_src)
if _ignore is not None:
ignored = ignore(_src, files)
else:
ignored = set()
for f in files:
if f not in ignored:
recursive_overwrite(os.path.join(_src, f),
os.path.join(_dest, f),
_ignore)
else:
shutil.copyfile(_src, _dest)
def main():
print('Downloading Update from HEAD...')
#Need the cert to access github
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.getcwd(), "cacert.pem")
#Get the Zipfile from Github
base_url='https://github.com/digiholic/universalSmashSystem/archive/master.zip'
page = urllib.urlopen(base_url)
#Download the zipfile
downloader = urllib.URLopener()
downloader.retrieve(page.geturl(), settingsManager.createPath('update.zip'))
#Extract it
updatezip = zipfile.ZipFile(settingsManager.createPath('update.zip'))
updatezip.extractall('tmp')
print('Copying files into game directory...')
#Copy the files upward, then remove the tmp files
tmp_path = settingsManager.createPath('tmp'+os.sep+'universalSmashSystem-master'+os.sep)
recursive_overwrite(tmp_path, settingsManager.createPath(''))
shutil.rmtree(tmp_path)
os.remove(settingsManager.createPath('update.zip'))
print('Done!')
if __name__ == '__main__': main()