forked from heldersepu/GMapCatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapUpdate.py
85 lines (75 loc) · 2.92 KB
/
mapUpdate.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
77
78
79
80
81
82
83
84
85
## @package gmapcatcher.mapUpdate
# All the update related logic
from mapConst import *
import gtk
from widgets.customMsgBox import updateMsgBox
import openanything
from threading import Timer
## Class used to get latest version info
class MapUpdate():
def __init__(self, strURL):
self.latest_version = "0.0.0.0"
self.latest_installer = ""
self.html_data = self.get_data(strURL)
if self.html_data:
splitList = self.html_data.split(SEPARATOR)
if len(splitList) == 2:
self.latest_version = splitList[0]
self.latest_installer = splitList[1]
## Return the data from the given URL
def get_data(self, strURL):
try:
oa = openanything.fetch(strURL)
if oa['status'] == 200:
return oa['data']
except Exception:
return False
## Class that should be called to check for updates
class CheckForUpdates():
def __init__(self, intDelay, strURL):
#Start after a few second delay
self.update = None
self.strURL = strURL
self.myThread = Timer(intDelay, self.UpdateThread)
self.myThread.start()
## Launch the MapUpdate in a thread to prevent any slowdowns
def UpdateThread(self):
self.update = MapUpdate(self.strURL)
## Finish the Thread and
def finish(self):
self.myThread.cancel()
if self.update:
if self.update.latest_version > VERSION:
updateMsgBox(
"Update detected! \n" +
("A new version of %s is available \n\n" % NAME) +
("Your version is %s \n" % VERSION) +
("Current version is %s" %
self.update.latest_version),
WEB_ADDRESS,
self.update.latest_installer
)
gtk.main()
if __name__ == "__main__":
# Test some URLs
URL_list = ["http://googlecode.com", "", "HTtp://Fake.url", None,
"http://htmltab.kb-creative.net",
"http://gmapcatcher.googlecode.com/svn/trunk/Changelog",
"http://gmapcatcher.googlecode.com/svn/wiki/version.wiki"]
# Once the version is up Test should "fail" for all but the last one!
for myURL in URL_list:
upd = MapUpdate(myURL)
print "|------------------------------------------------"
print "| Testing URL: ", myURL
print "| "
newVersionAvailable = upd.latest_version > VERSION
if newVersionAvailable:
print "| Your Version: ", VERSION
print "| "
print "| Latest Version: ", upd.latest_version
print "| Latest Installer: ", upd.latest_installer
if upd.html_data:
print "| HTML data: ", upd.html_data[:50]
print "| "
print "| New Version Available = ", newVersionAvailable
print "| "