def _upload_zip(zip_file: str, package_path: str, resolved_fs=None, force_upload: bool = False): packer = packaging.detect_packer_from_file(zip_file) if packer == packaging.PEX_PACKER and resolved_fs.exists(package_path): with tempfile.TemporaryDirectory() as tempdir: local_copy_path = os.path.join(tempdir, os.path.basename(package_path)) resolved_fs.get(package_path, local_copy_path) info_from_storage = PexInfo.from_pex(local_copy_path) into_to_upload = PexInfo.from_pex(zip_file) if not force_upload and info_from_storage.code_hash == into_to_upload.code_hash: _logger.info(f"skip upload of current {zip_file}" f" as it is already uploaded on {package_path}") return _logger.info(f"upload current {zip_file} to {package_path}") dir = os.path.dirname(package_path) if not resolved_fs.exists(dir): resolved_fs.mkdir(dir) resolved_fs.put(zip_file, package_path) # Remove previous metadata archive_meta_data = _get_archive_metadata_path(package_path) if resolved_fs.exists(archive_meta_data): resolved_fs.rm(archive_meta_data)
def upload_zip(zip_file: str, package_path: str = None): packer = packaging.detect_packer_from_file(zip_file) package_path, _, _ = packaging.detect_archive_names(packer, package_path) resolved_fs, path = filesystem.resolve_filesystem_and_path(package_path) with tempfile.TemporaryDirectory() as tempdir: parsed_url = parse.urlparse(zip_file) if parsed_url.scheme == "http": tmp_zip_file = os.path.join(tempdir, os.path.basename(parsed_url.path)) request.urlretrieve(zip_file, tmp_zip_file) zip_file = tmp_zip_file _upload_zip(zip_file, package_path, resolved_fs) return package_path