-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelv-ui-update.py
executable file
·76 lines (64 loc) · 2.02 KB
/
elv-ui-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
75
76
import os
import sys
import tempfile
import urllib2
import zipfile
import json
from StringIO import StringIO
from distutils.dir_util import copy_tree, remove_tree
def cleanup(zip_buffer, extracted_dir):
if zip_buffer:
zip_buffer.close()
if os.path.isdir(extracted_dir):
remove_tree(extracted_dir)
settings_stream = open("settings.json", "r")
settings = json.load(settings_stream)
dir_tmp = tempfile.gettempdir()
dir_extracted_root = ""
dir_backup = os.path.join(dir_tmp, "ElvUIBackup")
dir_addons = "%s/Interface/AddOns/" % settings['dir_wow']
git_repo_url = "https://git.tukui.org/elvui/elvui/-/archive/master/elvui-master.zip"
try:
print ("Downloading latest Elv UI...")
response = urllib2.urlopen(git_repo_url)
data = response.read()
except urllib2.URLError:
print("Failed to download data from %s" % git_repo_url)
exit(1)
# write the data to a file-like object in memory
buff = StringIO(data)
# extract the core and config dirs from the zip file
try:
print ("Extracting zip to %s" % dir_tmp)
with zipfile.ZipFile(buff, "r") as zip_fp:
namelist = zip_fp.namelist()
if ".git" in namelist:
del namelist[".git"]
zip_fp.extractall(dir_tmp)
dir_extracted_root = os.path.join(dir_tmp, namelist[0])
except zipfile.BadZipfile:
print("Downloaded zip file is not valid")
cleanup(buff, dir_extracted_root)
exit(1)
except RuntimeError:
print("Failed to extract contents of zip")
cleanup(buff, dir_extracted_root)
exit(1)
# Create a backup
try:
print ("Backing up current folder to %s" % dir_backup)
copy_tree(dir_extracted_root, dir_backup)
except RuntimeError as e:
print e
print("Failed to create backup; aborting")
cleanup(buff, dir_extracted_root)
exit(1)
# overwrite the files with the new ones
try:
print ("Copying extract to %s" % dir_addons)
copy_tree(dir_extracted_root, dir_addons)
except:
print("Error copying files to addons dir")
finally:
cleanup(buff, dir_extracted_root)
print("Done")