def checkUpdate(currentVersion, singleLine=True, showErrormsg=False): """ check if an update of B3 is available """ timeout = 5 ## urllib2.urlopen support the timeout argument only from 2.6... too bad ## instead we alter the default socket timeout import socket original_timeout = socket.getdefaulttimeout() socket.setdefaulttimeout(timeout) if not singleLine: sys.stdout.write("checking for updates... \n") message = None errorMessage = None try: f = urllib2.urlopen(URL_B3_LATEST_VERSION) _xml = ElementTree.parse(f) latestVersion = _xml.getroot().text not singleLine and sys.stdout.write( "latest B3 version is %s\n" % latestVersion) _lver = version.LooseVersion(latestVersion) _cver = version.LooseVersion(currentVersion) if _cver < _lver: if singleLine: message = "*** NOTICE: A newer version of B3 is available. See www.bigbrotherbot.net! ***" else: message = """ _\|/_ (o o) +----oOO-{_}-OOo---------------------+ | | | | | A newer version of B3 is available | | See www.bigbrotherbot.net | | | | | +------------------------------------+ """ except IOError, e: if hasattr(e, 'reason'): errorMessage = "%s" % e.reason elif hasattr(e, 'code'): errorMessage = "error code: %s" % e.code else: errorMessage = "%s" % e
def checkUpdate(currentVersion, singleLine=True, showErrormsg=False): """ check if an update of B3 is available """ timeout = 5 ## urllib2.urlopen support the timeout argument only from 2.6... too bad ## instead we alter the default socket timeout import socket original_timeout = socket.getdefaulttimeout() socket.setdefaulttimeout(timeout) if not singleLine: sys.stdout.write("checking for updates... \n") message = None errorMessage = None try: f = urllib2.urlopen(URL_B3_LATEST_VERSION) _xml = ElementTree.parse(f) latestVersion = _xml.getroot().text not singleLine and sys.stdout.write("latest B3 version is %s\n" % latestVersion) _lver = version.LooseVersion(latestVersion) _cver = version.LooseVersion(currentVersion) if _cver < _lver: if singleLine: message = "*** NOTICE: A newer version of B3 is available. See www.bigbrotherbot.net! ***" else: message = """ _\|/_ (o o) +----oOO-{_}-OOo---------------------+ | | | | | A newer version of B3 is available | | See www.bigbrotherbot.net | | | | | +------------------------------------+ """ except IOError, e: if hasattr(e, 'reason'): errorMessage = "%s" % e.reason elif hasattr(e, 'code'): errorMessage = "error code: %s" % e.code else: errorMessage = "%s" % e
def checkUpdate(currentVersion, singleLine=True, showErrormsg=False): """ check if an update of B3 is available """ if not singleLine: sys.stdout.write("checking for updates... \n") message = None errorMessage = None try: f = urllib2.urlopen('http://www.bigbrotherbot.net/version.xml') _xml = ElementTree.parse(f) latestVersion = _xml.getroot().text _lver = version.LooseVersion(latestVersion) _cver = version.LooseVersion(currentVersion) if _cver < _lver: if singleLine: message = "*** NOTICE: A newer version of B3 is available. See www.bigbrotherbot.net! ***" else: message = """ _\|/_ (o o) +----oOO-{_}-OOo---------------------+ | | | | | A newer version of B3 is available | | See www.bigbrotherbot.net | | | | | +------------------------------------+ """ except IOError, e: if hasattr(e, 'reason'): errorMessage = "%s" % e.reason elif hasattr(e, 'code'): errorMessage = "error code: %s" % e.code else: errorMessage = "%s" % e