forked from Podshot/MCEdit-Filters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate Filters.py
39 lines (36 loc) · 1.5 KB
/
Update Filters.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
import glob, urllib2, urllib, json, os, webbrowser
displayName = "Update Filters"
METHOD = "[Update Filters]"
inputs = (
("Remove Old Filters?", True),
("View Change Logs", False),
)
def perform(level, box, options):
doRemove = options["Remove Old Filters?"]
changeLog = options["View Change Logs"]
filters = glob.glob("*.py")
for filt in filters:
try:
fileName = filt.split(".")
name = fileName[0]
py = __import__(name)
filterUpdateURL = str(py.UPDATE_URL)
filterVersion = str(py.VERSION)
site = urllib2.urlopen(filterUpdateURL)
response = site.read()
jsonRaw = json.loads(response)
if filterVersion != str(jsonRaw["Version"]):
urllib.urlretrieve(str(jsonRaw["Download-URL"]), str(jsonRaw["Name"]))
print '%s: Updated "%s" from version %s to version %s' % (METHOD, py.displayName, py.VERSION, str(jsonRaw["Version"]))
if doRemove:
os.remove(filt)
if changeLog:
if "ChangeLog" in jsonRaw:
log = str(jsonRaw["ChangeLog"])
webbrowser.open_new_tab(log)
else:
print '%s: Filter "%s" did not have a Change Log' % (METHOD, py.displayName)
else:
print '%s: %s\'s version matched update the site\'s version' % (METHOD, py.displayName)
except:
pass