From 2cfb59d0428b3b22b540bd5e7bfc156bbd4f9f75 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 5 Jun 2020 16:09:27 +0100 Subject: [PATCH] Return dictionary of package to deps in API --- app/blueprints/api/endpoints.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/blueprints/api/endpoints.py b/app/blueprints/api/endpoints.py index b0c36934..d5ef9d08 100644 --- a/app/blueprints/api/endpoints.py +++ b/app/blueprints/api/endpoints.py @@ -53,12 +53,13 @@ def package(package): return jsonify(package.getAsDictionary(current_app.config["BASE_URL"])) -@bp.route("/api/packages///dependencies/") -@is_package_page -def package_dependencies(package): - ret = [] +def resolve_package_deps(out, package, only_hard): + id = package.getId() + if id in out: + return - only_hard = request.args.get("only_hard") + ret = [] + out[id] = ret for dep in package.dependencies: if only_hard and dep.optional: @@ -70,10 +71,12 @@ def package_dependencies(package): if dep.package: name = dep.package.name fulfilled_by = [ dep.package.getId() ] + resolve_package_deps(out, dep.package, only_hard) elif dep.meta_package: name = dep.meta_package.name fulfilled_by = [ pkg.getId() for pkg in dep.meta_package.packages] + # TODO: resolve most likely candidate else: raise "Malformed dependency" @@ -84,7 +87,16 @@ def package_dependencies(package): "packages": fulfilled_by }) - return jsonify(ret) + +@bp.route("/api/packages///dependencies/") +@is_package_page +def package_dependencies(package): + only_hard = request.args.get("only_hard") + + out = {} + resolve_package_deps(out, package, only_hard) + + return jsonify(out) @bp.route("/api/packages///releases/")