def _check_is_item_in_remote_registry(public_id: PublicId, item_type_plural: str) -> None: """ Check if an item is in the remote registry. :param public_id: the public id. :param item_type_plural: the type of the item. :return: None :raises click.ClickException: if the item is not present. """ get_package_meta(item_type_plural[:-1], public_id)
def fetch_package(obj_type: str, public_id: PublicId, cwd: str, dest: str) -> Path: """ Fetch a package (connection/contract/protocol/skill) from Registry. :param obj_type: str type of object you want to fetch: 'connection', 'protocol', 'skill' :param public_id: str public ID of object. :param cwd: str path to current working directory. :return: package path """ logger.debug("Fetching {obj_type} {public_id} from Registry...".format( public_id=public_id, obj_type=obj_type)) logger.debug("Downloading {obj_type} {public_id}...".format( public_id=public_id, obj_type=obj_type)) package_meta = get_package_meta(obj_type, public_id) file_url = package_meta["file"] filepath = download_file(file_url, cwd) # next code line is needed because the items are stored in tarball packages as folders dest = os.path.split(dest)[0] logger.debug("Extracting {obj_type} {public_id}...".format( public_id=public_id, obj_type=obj_type)) extract(filepath, dest) logger.debug("Successfully fetched {obj_type} '{public_id}'.".format( public_id=public_id, obj_type=obj_type)) package_path = os.path.join(dest, public_id.name) return Path(package_path)
def get_package_latest_public_id(package_id: PackageId) -> PublicId: """ Get package latest package id from the remote repo. :param package_id: id of the package to check :return: package id of the latest package in remote repo """ package_meta = get_package_meta(str(package_id.package_type), package_id.public_id.to_latest()) return PublicId.from_str(package_meta["public_id"])
def test_get_package_meta(): """Test get package meta.""" package_meta = get_package_meta("protocol", DefaultMessage.protocol_id.to_latest()) assert isinstance(package_meta, dict) assert package_meta["name"] == DefaultMessage.protocol_id.name