def configure(self, url=None, token=None, test=False): """ Configure the api to use given url and token or to get them from the Config. """ if url is None: url = Config.get_value("url") if token is None: token = Config.get_value("token") self.server_url = url self.auth_header = {"Authorization": "Basic {0}".format(token)} self.configured = True if test: self.test_connection() Config.set("url", url) Config.set("token", token)
def should_update(): from xmlrpc.client import ServerProxy from distutils.version import StrictVersion from datetime import datetime import calendar current_version = StrictVersion(__version__) last_value = (Config.has_name("needs_update") and Config.get_value("needs_update") == "1") last_version = (0, 0, 0) if Config.has_name("last_version"): last_version = StrictVersion(Config.get_value("last_version")) # Return false if an upgrade has happened if last_value and (last_version < current_version): return False Config.set("last_version", __version__) # Next lets check the time last_time = None if Config.has_name("last_update_check"): last_time = datetime.utcfromtimestamp( int(Config.get_value("last_update_check"))) else: last_time = datetime.now() if (last_time - datetime.now()).days < 7: return False Config.set("last_update_check", calendar.timegm(datetime.now().timetuple())) # Lastly lets check pypi for versions pypi = ServerProxy("http://pypi.python.org/pypi") pypiversion = StrictVersion(pypi.package_releases("tmc")[0]) if pypiversion > current_version: return True return False
def should_update(): from xmlrpc.client import ServerProxy from distutils.version import StrictVersion from datetime import datetime import calendar current_version = StrictVersion(__version__) last_value = (Config.has_name("needs_update") and Config.get_value("needs_update") == "1") last_version = (0, 0, 0) if Config.has_name("last_version"): last_version = StrictVersion(Config.get_value("last_version")) # Return false if an upgrade has happened if last_value and (last_version < current_version): return False Config.set("last_version", __version__) # Next lets check the time last_time = None if Config.has_name("last_update_check"): last_time = datetime.utcfromtimestamp(int( Config.get_value("last_update_check"))) else: last_time = datetime.now() if (last_time - datetime.now()).days < 7: return False Config.set("last_update_check", calendar.timegm(datetime.now().timetuple())) # Lastly lets check pypi for versions pypi = ServerProxy("http://pypi.python.org/pypi") pypiversion = StrictVersion(pypi.package_releases("tmc")[0]) if pypiversion > current_version: return True return False