def deprecated(self, key): value = self.get(key) if value is not None: logger.info( '%s is using the deprecated `%s` configuration, which will not be supported in Mechanic 2.', self.get('name'), key) return value
def deprecated(self, key): value = self.get(key) if value is not None: logger.info('%s is using the deprecated `%s` configuration, which will not be supported in Mechanic 2.', self.get('name'), key) return value
def log(target): if hasattr(target, 'im_class'): logger.info('Calling `%s#%s` in a new thread', target.im_class.__name__, target.__name__) else: logger.info('Initializing `%s` in a new thread', target.__name__)
def extensions(self): logger.info("fetching extensions from %s..." % self.base_url) try: response = requests.get(self.url) response.raise_for_status() return response.json() except requests.ConnectionError: raise Registry.ConnectionError
def _get_cached(cls): logger.info("Fetching cached updates...") cache = Storage.get('update_cache') extensions = [Extension(name=name) for name, _ in cache.items()] for extension in extensions: if extension.is_installed and extension.is_configured: extension.remote.version = Version(cache[extension.name]) return extensions
def _fetch_updates(cls): logger.info("Fetching updates...") try: updates = [e for e in Extension.all() if e.should_update] except requests.ConnectionError: raise Update.ConnectionError cls._set_cached(updates) Storage.set('last_checked_at', time.time()) return updates
def get_cached(self, url): headers = {} cached_response = self.cache.get(url, None) if cached_response is not None: etag = self.get_etag(cached_response) headers['If-None-Match'] = etag response = requests.get(url, headers=headers) self.log_header(response, 'x-ratelimit-limit') self.log_header(response, 'x-ratelimit-remaining') if response.status_code == 304: logger.info('Using cached response for {}'.format(self.url)) response = cached_response response.raise_for_status() return response
def __init__(self, force=False): try: self.updates = self.get_updates(force) except Update.ConnectionError: logger.info("Couldn't connect to the internet") return if self.updates: self.create_image() self.w.title = TextBox((105, 20, -20, 20), self.title) self.w.explanation = TextBox((105, 45, -20, 50), self.explanation) self.w.updateButton = Button((-150, -40, 130, 20), "Install Updates", callback=self.do_update) self.w.cancelButton = Button((-255, -40, 90, 20), "Not Now", callback=self.cancel) self.w.showDetailsButton = Button((105, -40, 110, 20), "Show Details", callback=self.show_details) self.w.setDefaultButton(self.w.updateButton) self.w.open() else: logger.info("All extensions are up to date.")
def get_with_etag_cache(self, url): headers = {} cached_response = self.cache.get(url, None) if cached_response is not None: etag = self.get_etag(cached_response) headers['If-None-Match'] = etag logger.debug('Headers: %s', headers) response = requests.get(url, headers=headers, auth=NullAuth()) self.log_header(response, 'x-ratelimit-limit') self.log_header(response, 'x-ratelimit-remaining') if response.status_code == 304: logger.info('Using cached response for {}'.format(self.url)) response = cached_response response.raise_for_status() return response
def check_for_updates(self): """Open updates window unless ran in last hour""" if self.should_check_for_updates(): try: skip_patches = bool(Storage.get('ignore_patch_updates')) updates = Update.all(force=True, skip_patches=skip_patches) except Update.ConnectionError: logger.info("Couldn't connect to the internet") return if updates: logger.info("%d new updates found", len(updates)) Bus().emit("newUpdatesFound", updates) else: logger.info("No new updates found") else: logger.info("Skipping a check for new updates")
def get(self): logger.info('Requesting {}'.format(self.url)) return self.cache_response(self.url, self.get_cached(self.url))
def add(self, **data): logger.info("posting extension to %s..." % self.base_url) return requests.post(self.url, data=data)
def set_defaults(cls, **defaults): for key, default in defaults.items(): value = cls.get(key) if value is None: logger.info('Setting default value for %s to %s' % (key, default)) cls.set(key, default)