Beispiel #1
0
 def fetch_index(self):
     if not self.url:
         return {}
     index_url = urljoin(self.url, 'index.json')
     response = self.geturl(index_url)
     if response.status_code != http.client.OK:
         message = 'Could not fetch "{}"; recieved "{} {}"'
         self.logger.error(
             message.format(index_url, response.status_code,
                            response.reason))
         return {}
     if sys.version_info[0] == 3:
         content = response.content.decode('utf-8')
     else:
         content = response.content
     return json.loads(content)
Beispiel #2
0
 def fetch_index(self):
     if not self.url:
         return {}
     index_url = urljoin(self.url, 'index.json')
     response = self.geturl(index_url)
     if response.status_code != http.client.OK:
         message = 'Could not fetch "{}"; recieved "{} {}"'
         self.logger.error(message.format(index_url,
                                          response.status_code,
                                          response.reason))
         return {}
     if sys.version_info[0] == 3:
         content = response.content.decode('utf-8')
     else:
         content = response.content
     return json.loads(content)
Beispiel #3
0
 def download_asset(self, asset, owner_name):
     url = urljoin(self.url, owner_name, asset['path'])
     local_path = _f(
         os.path.join(settings.dependencies_directory, '__remote',
                      owner_name, asset['path'].replace('/', os.sep)))
     if os.path.exists(local_path) and not self.always_fetch:
         local_sha = sha256(local_path)
         if local_sha == asset['sha256']:
             self.logger.debug('Local SHA256 matches; not re-downloading')
             return local_path
     self.logger.debug('Downloading {}'.format(url))
     response = self.geturl(url, stream=True)
     if response.status_code != http.client.OK:
         message = 'Could not download asset "{}"; recieved "{} {}"'
         self.logger.warning(
             message.format(url, response.status_code, response.reason))
         return
     with open(local_path, 'wb') as wfh:
         for chunk in response.iter_content(chunk_size=self.chunk_size):
             wfh.write(chunk)
     return local_path
Beispiel #4
0
 def download_asset(self, asset, owner_name):
     url = urljoin(self.url, owner_name, asset['path'])
     local_path = _f(os.path.join(settings.dependencies_directory, '__remote',
                                  owner_name, asset['path'].replace('/', os.sep)))
     if os.path.exists(local_path) and not self.always_fetch:
         local_sha = sha256(local_path)
         if local_sha == asset['sha256']:
             self.logger.debug('Local SHA256 matches; not re-downloading')
             return local_path
     self.logger.debug('Downloading {}'.format(url))
     response = self.geturl(url, stream=True)
     if response.status_code != http.client.OK:
         message = 'Could not download asset "{}"; recieved "{} {}"'
         self.logger.warning(message.format(url,
                                            response.status_code,
                                            response.reason))
         return
     with open(local_path, 'wb') as wfh:
         for chunk in response.iter_content(chunk_size=self.chunk_size):
             wfh.write(chunk)
     return local_path