pesterchum/version.py

90 lines
2.6 KiB
Python
Raw Normal View History

2011-05-26 03:40:30 -04:00
import urllib
import re
import time
2011-06-27 00:56:29 -04:00
USER_TYPE = "edge"
# user - for normal people
# beta - for the original beta testers
# dev - used to be for git users, now it's anyone with the 3.41 beta
# edge - new git stuff. bleeding edge, do not try at home (kiooeht version)
2011-05-26 03:40:30 -04:00
2011-06-26 17:37:28 -04:00
_pcMajor = "3.41"
_pcMinor = "2"
_pcStatus = "B" # A = alpha
# B = beta
# RC = release candidate
# None = public release
2011-06-19 08:32:33 -04:00
_pcRevision = "5"
2011-05-26 03:40:30 -04:00
_pcVersion = ""
def pcVerCalc():
global _pcVersion
if _pcStatus:
_pcVersion = "%s.%s-%s%s" % (_pcMajor, _pcMinor, _pcStatus, _pcRevision)
else:
_pcVersion = "%s.%s.%s" % (_pcMajor, _pcMinor, _pcRevision)
def lexVersion(short=False):
if not _pcStatus:
return "%s.%s" % (_pcMajor, _pcMinor)
utype = ""
if USER_TYPE == "edge":
utype = "E"
if short:
return "%s.%s%s%s%s" % (_pcMajor, _pcMinor, _pcStatus, _pcRevision, utype);
stype = ""
if _pcStatus == "A":
stype = "Alpha"
elif _pcStatus == "B":
stype = "Beta"
elif _pcStatus == "RC":
stype = "Release Candidate"
if utype == "E":
utype = " Bleeding Edge"
return "%s.%s %s %s%s" % (_pcMajor, _pcMinor, stype, _pcRevision, utype);
# Naughty I know, but it lets me grab it from the bash script.
if __name__ == "__main__":
print lexVersion()
def verStrToNum(ver):
w = re.match("(\d+\.?\d+)\.(\d+)-?([A-Za-z]{0,2})\.?(\d*):(\S+)", ver)
if not w:
print "Update check Failure: 3"; return
full = ver[:ver.find(":")]
return full,w.group(1),w.group(2),w.group(3),w.group(4),w.group(5)
def updateCheck(q,num):
time.sleep(3)
data = urllib.urlencode({"type" : USER_TYPE})
try:
f = urllib.urlopen("http://distantsphere.com/pesterchum.php?" + data)
except:
print "Update check Failure: 1"; return q.put((False,1))
newest = f.read()
f.close()
if not newest or newest[0] == "<":
print "Update check Failure: 2"; return q.put((False,2))
try:
(full, major, minor, status, revision, url) = verStrToNum(newest)
except TypeError:
return q.put((False,3))
print full
if major <= _pcMajor:
if minor <= _pcMinor:
if status:
if status <= _pcStatus:
if revision <= _pcRevision:
return q.put((False,0))
else:
if not _pcStatus:
if revision <= _pcRevision:
return q.put((False,0))
print "A new version of Pesterchum is avaliable!"
q.put((full,url))