def __init__(self, oauth, version, installation_step, purge_on_delete=False): self.version = version # Construct and set the package_zip file if self.version.number: self.package_zip = PackageZipBuilder( self.version.package.namespace, self.version.number).install_package() elif self.version.zip_url or self.version.repo_url: if self.version.repo_url: repo_url = self.version.repo_url git_ref = self.version.branch if installation_step.installation.git_ref: git_ref = installation_step.installation.git_ref if installation_step.installation.fork: repo_url_parts = repo_url.split('/') repo_url_parts[3] = installation_step.installation.fork repo_url = '/'.join(repo_url_parts) zip_url = '%s/archive/%s.zip' % (repo_url, git_ref) else: zip_url = self.version.zip_url # Deploy a zipped bundled downloaded from a url try: zip_resp = requests.get(zip_url) except: raise ValueError('Failed to fetch zip from %s' % self.version.zip_url) zipfp = TemporaryFile() zipfp.write(zip_resp.content) zipfile = ZipFile(zipfp, 'r') if not self.version.subfolder and not self.version.repo_url: zipfile.close() zipfp.seek(0) self.package_zip = base64.b64encode(zipfp.read()) else: ignore_prefix = '' if self.version.repo_url: # Get the top level folder from the zip ignore_prefix = '%s/' % zipfile.namelist()[0].split('/')[0] # Extract a subdirectory from the zip subdirectory = ignore_prefix + self.version.subfolder subzip = zip_subfolder(zipfile, subdirectory, self.version.namespace_token, self.version.namespace) subzipfp = subzip.fp subzip.close() subzipfp.seek(0) self.package_zip = base64.b64encode(subzipfp.read()) super(ApiInstallVersion, self).__init__(oauth, self.package_zip, installation_step, purge_on_delete)
def __init__(self, oauth, version, installation_step, purge_on_delete=False): self.version = version # Construct and set the package_zip file if self.version.number: self.package_zip = PackageZipBuilder(self.version.package.namespace, self.version.number).install_package() elif self.version.zip_url or self.version.repo_url: if self.version.repo_url: repo_url = self.version.repo_url git_ref = self.version.branch if installation_step.installation.git_ref: git_ref = installation_step.installation.git_ref if installation_step.installation.fork: repo_url_parts = repo_url.split('/') repo_url_parts[3] = installation_step.installation.fork repo_url = '/'.join(repo_url_parts) zip_url = '%s/archive/%s.zip' % (repo_url, git_ref) else: zip_url = self.version.zip_url # Deploy a zipped bundled downloaded from a url try: zip_resp = requests.get(zip_url) except: raise ValueError('Failed to fetch zip from %s' % self.version.zip_url) zipfp = TemporaryFile() zipfp.write(zip_resp.content) zipfile = ZipFile(zipfp, 'r') if not self.version.subfolder and not self.version.repo_url: zipfile.close() zipfp.seek(0) self.package_zip = base64.b64encode(zipfp.read()) else: ignore_prefix = '' if self.version.repo_url: # Get the top level folder from the zip ignore_prefix = '%s/' % zipfile.namelist()[0].split('/')[0] # Extract a subdirectory from the zip subdirectory = ignore_prefix + self.version.subfolder subzip = zip_subfolder(zipfile, subdirectory, self.version.namespace_token, self.version.namespace) subzipfp = subzip.fp subzip.close() subzipfp.seek(0) self.package_zip = base64.b64encode(subzipfp.read()) super(ApiInstallVersion, self).__init__(oauth, self.package_zip, installation_step, purge_on_delete)
def load_repo_metadata(self, subpath): # Download a copy of the head commit on the branch as a zip file response = requests.get('https://github.com/%s/%s/archive/%s.zip' % (self.github_owner, self.github_repo, self.branch)) # Parse filename from the Content-Disposition header to add before path filename = response.headers['content-disposition'].split('; filename=')[-1] filename = filename.replace('.zip', '') repo_fp = StringIO.StringIO() repo_fp.write(response.content) repo_zip = ZipFile(repo_fp, 'r') subfolder = filename if subpath: subfolder += '/%s' % subpath self.repo = zip_subfolder(repo_zip, subfolder)
def load_repo_metadata(self, subpath): # Download a copy of the head commit on the branch as a zip file response = requests.get( 'https://github.com/%s/%s/archive/%s.zip' % (self.github_owner, self.github_repo, self.branch)) # Parse filename from the Content-Disposition header to add before path filename = response.headers['content-disposition'].split( '; filename=')[-1] filename = filename.replace('.zip', '') repo_fp = StringIO.StringIO() repo_fp.write(response.content) repo_zip = ZipFile(repo_fp, 'r') subfolder = filename if subpath: subfolder += '/%s' % subpath self.repo = zip_subfolder(repo_zip, subfolder)
def load_org_metadata(self, oauth): # Get the metadata from the org org_metadata = ApiRetrievePackaged(oauth, self.package_name)() # Zip the package name folder's contents from the zip as a new zip self.org_metadata = zip_subfolder(org_metadata, self.package_name)