示例#1
0
 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
示例#2
0
 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
示例#3
0
 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__)
示例#4
0
 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
示例#5
0
 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
示例#6
0
    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
示例#7
0
    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
示例#8
0
    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
示例#9
0
    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.")
示例#10
0
    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
示例#11
0
    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")
示例#12
0
 def get(self):
     logger.info('Requesting {}'.format(self.url))
     return self.cache_response(self.url, self.get_cached(self.url))
示例#13
0
 def add(self, **data):
     logger.info("posting extension to %s..." % self.base_url)
     return requests.post(self.url, data=data)
示例#14
0
 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)
示例#15
0
 def add(self, **data):
     logger.info("posting extension to %s..." % self.base_url)
     return requests.post(self.url, data=data)