def publish_demo_component(self, demo_file_url): # download zip component file root_directory = os.path.join(tempfile.gettempdir(), str(uuid.uuid4())) if not Path.exists(Path(root_directory)): os.mkdir(root_directory) component_name = download_file_from_url(demo_file_url, root_directory) # extract the zip file extracted_file = os.path.join( root_directory, component_name.split(".")[0].split("_")[1]) extract_zip_file(os.path.join(root_directory, component_name), extracted_file) # prepare tar file output_path = os.path.join( root_directory, component_name.split(".")[0].split("_")[1] + '.tar.gz') make_tarfile(source_dir=extracted_file, output_filename=output_path) # upload demo file to s3 and demo attributes key = f"assets/{self.org_id}/{self.service_id}/component.tar.gz" boto_utils.s3_upload_file(filename=output_path, bucket=ASSETS_COMPONENT_BUCKET_NAME, key=key) new_demo_url = f"https://{ASSETS_COMPONENT_BUCKET_NAME}.s3.amazonaws.com/{key}" return new_demo_url
def _extract_zip_and_and_tar(self, org_id, service_id, s3_url): root_directory = ASSET_TEMP_EXTRACT_DIRECTORY zip_directory = root_directory + org_id + "/" + service_id extracted_zip_directory = root_directory + "extracted/" + org_id + "/" + service_id zip_file_name = download_file_from_url(s3_url, zip_directory) zip_file_path = zip_directory + "/" + zip_file_name extracted_file_path = extracted_zip_directory + "/" + zip_file_name.split(".")[0].split("_")[1] extract_zip_file(zip_file_path, extracted_file_path) tar_file_path = extracted_file_path + ".tar.gz" make_tarfile(tar_file_path, extracted_file_path) return tar_file_path
def upload_proto_file_from_hash_to_bucket(self, org_id, service_id, asset_hash): temp_dir = tempfile.gettempdir() base_path = os.path.join(temp_dir, str(uuid.uuid1())) if not os.path.exists(base_path): os.makedirs(base_path) temp_download_path = os.path.join(base_path, 'proto.tar') temp_extraction_path = os.path.join(base_path, 'proto') temp_output_path = os.path.join(base_path, 'proto.tar.gz') io_bytes = self._ipfs_util.read_bytesio_from_ipfs(asset_hash) with open(temp_download_path, 'wb') as outfile: outfile.write(io_bytes.getbuffer()) extract_zip_file(zip_file_path=temp_download_path, extracted_path=temp_extraction_path) make_tarfile(source_dir=temp_extraction_path, output_filename=temp_output_path) self._s3_util.push_file_to_s3(temp_output_path, ASSETS_COMPONENT_BUCKET_NAME, f"assets/{org_id}/{service_id}/proto.tar.gz")