INNER CODE UNIT · Python
list_has_binary
ExplosionEngine/Explosion · ThirdParty/ConanRecipes/build_recipes.py:146
def list_has_binary(list_json: str, reference: str, package_id: str) -> bool:
# 'conan list' reports each scope (the local cache or a remote) as either an {"error": ...} payload
# when the reference is absent, or a revisions -> packages tree when it is present; the binary exists
# there only if our package id shows up under some revision of that tree.
name_version = reference.split("#", 1)[0]
try:
data = json.loads(list_json)
except json.JSONDecodeError:
return False
for scope in data.values():
if not isinstance(scope, dict) or "error" in scope:
continue
revisions = (scope.get(name_version) or {}).get("revisions") or {}
for revision in revisions.values():
if package_id in (revision.get("packages") or {}):
return True
return False