def download_release(repo=None, file_name=None, version='master', file_type='zipball'): """ Download a release as a zip or tar file\n :param repo: a project/repository partial URL (Example: OneView-TestTools/tru)\n :file_name: The local file name to save as\n :param version: Optional release version to download (defaults to 'master') (Example: 2.1.1.24)\n :param file_type: The file type - one of 'tarball' or 'zipball' (default is zipball)\n :return: full local path to downloaded file\n Examples: | =Keyword= | =Repository= | =Local File Name= | =Version= | =File Type= | | Download GitHub Release | OneView-TestTools/tru | tru-2.1.1.20.zip | 2.1.1.20 | zipball | | Download GitHub Release | OneView-TestTools/tru | tru.zip | | Download GitHub Release | OneView-TestTools/tru | tru.zip | 2.1.1.20 | """ if repo is None: raise exceptions.NonFatalError('No GitHub repository URL provided') # build the URL url = ROOT_URL + 'repos/' + repo.strip( '/') + '/' + file_type + '/' + version.strip('/') # create the request session with requests.Session() as session: resp = session.get(url, stream=True) if resp.status_code != 200: raise exceptions.NonFatalError( 'Download request to GitHub failed: {}'.format(resp.text)) # if the filename wasn't set, get the default from the headers if file_name is None: file_name = resp.headers.get('Content-Disposition').split( '=')[-1] # save the stream to the output file file_path = path.abspath(file_name) logger.debug("Downloading %s and saving as %s", url, file_path) with open(file_path, 'wb') as fout: for chunk in resp.iter_content(chunk_size=1024): if chunk: fout.write(chunk) # make sure it downloaded if not path.exists(file_path): raise exceptions.NonFatalError( 'Failed to download from {}'.format(url)) return file_path
def get_releases(repo=None): """ Retrieve the release names for a specific repository.\n :param repo: a project/repository partial URL (Example: OneView-TestTools/tru)\n :return: list of versions\n Examples: | =Keyword= | =GitHub Project/Repo= | | Get GitHub Releases | OneView-TestTools/tru | """ if repo is None: raise exceptions.NonFatalError('No GitHub repository URL provided') with requests.Session() as session: full_url = ROOT_URL + 'repos/' + repo + '/releases' resp = session.get(full_url) # check the response status code if resp.status_code == 404: raise GitHubRepositoryNotFoundException( 'Repository not found: {}'.format(full_url)) return [i.get('name') for i in json.loads(resp.text)]
def wrapper(self, *args, **kwargs): resp = decorated(self, *args, **kwargs) if resp.status_code not in [200, 201, 202, 203, 204]: raise exceptions.NonFatalError( 'HTTP request was not successful. {}'.format(resp.status_code)) return resp
def wrapper(self, *args, **kwargs): output = decorated(self, *args, **kwargs) failures = re.compile('(?i)error|fail') if failures.search(output): raise exceptions.NonFatalError( 'SSH command(s) failed. {}'.format(output))
def wrapper(self, *args, **kwargs): if self._host is None: raise exceptions.NonFatalError( 'No HTTP session to ToxiProxy host\port. Need to issue Connect first!' ) return decorated(self, *args, **kwargs)