1 |
import urllib2, ConfigParser, platform |
2 |
import socket |
3 |
|
4 |
class VersionCheck: |
5 |
def __init__(self): |
6 |
self.url = "http://ascend.cruncher2.dyndns.org/version.ini" |
7 |
self.download = None |
8 |
self.latest = None |
9 |
self.info = None |
10 |
def check(self): |
11 |
socket.setdefaulttimeout(1) |
12 |
auth_handler = urllib2.HTTPBasicAuthHandler() |
13 |
opener = urllib2.build_opener(auth_handler) |
14 |
urllib2.install_opener(opener) |
15 |
fp = urllib2.urlopen(self.url) |
16 |
|
17 |
cp = ConfigParser.SafeConfigParser() |
18 |
cp.readfp(fp,self.url) |
19 |
|
20 |
opersys = platform.system() |
21 |
|
22 |
if opersys=="Windows": |
23 |
self.vertype = "Windows" |
24 |
self.latest = cp.get('Windows','version').strip() |
25 |
self.info = cp.get('Windows','info').strip() |
26 |
try: |
27 |
self.download = cp.get('Windows','download').strip() |
28 |
except: |
29 |
pass |
30 |
return True |
31 |
else: |
32 |
self.vertype = "Source code" |
33 |
self.latest = cp.get('Generic','version').strip() |
34 |
self.info = cp.get('Generic','info').strip() |
35 |
try: |
36 |
self.download = cp.get('Generic','download').strip() |
37 |
except: |
38 |
pass |
39 |
return True |
40 |
|
41 |
raise RuntimeError("No version info available for this operating system") |
42 |
|
43 |
if __name__=="__main__": |
44 |
v = VersionCheck() |
45 |
if v.check(): |
46 |
print v.latest |
47 |
print "Info at %s" % v.info |
48 |
if v.download: |
49 |
print "Download from %s" % v.download |