Add basic dependency resolution

This commit is contained in:
rubenwardy 2019-09-03 00:42:51 +01:00
parent cc564af44e
commit 4082863b5a
4 changed files with 40 additions and 2 deletions

@ -398,7 +398,7 @@ class Package(db.Model):
forums = db.Column(db.Integer, nullable=True)
provides = db.relationship("MetaPackage", secondary=provides, lazy="subquery",
backref=db.backref("packages", lazy="dynamic"))
backref=db.backref("packages", lazy="dynamic", order_by=db.desc("score")))
dependencies = db.relationship("Dependency", backref="depender", lazy="dynamic", foreign_keys=[Dependency.depender_id])
@ -441,6 +441,13 @@ class Package(db.Model):
else:
return "ready"
def getAsDictionaryKey(self):
return {
"name": self.name,
"author": self.author.display_name,
"type": self.type.toName(),
}
def getAsDictionaryShort(self, base_url, version=None, protonum=None):
tnurl = self.getThumbnailURL(1)
release = self.getDownloadRelease(version=version, protonum=protonum)

@ -32,12 +32,42 @@ def api_packages_page():
for package in query.all()]
return jsonify(pkgs)
@app.route("/api/packages/<author>/<name>/")
@is_package_page
def api_package_page(package):
return jsonify(package.getAsDictionary(app.config["BASE_URL"]))
@app.route("/api/packages/<author>/<name>/dependencies/")
@is_package_page
def api_package_deps_page(package):
ret = []
for dep in package.dependencies:
name = None
fulfilled_by = None
if dep.package:
name = dep.package.name
fulfilled_by = [ dep.package.getAsDictionaryKey() ]
elif dep.meta_package:
name = dep.meta_package.name
fulfilled_by = [ pkg.getAsDictionaryKey() for pkg in dep.meta_package.packages]
else:
raise "Malformed dependency"
ret.append({
"name": name,
"is_optional": dep.optional,
"packages": fulfilled_by
})
return jsonify(ret)
@app.route("/api/topics/")
def api_topics_page():
qb = QueryBuilder(request.args)

@ -33,5 +33,6 @@ services:
- config.env
volumes:
- "./data/uploads:/home/cdb/app/public/uploads"
- "./app:/home/cdb/app"
depends_on:
- redis

@ -18,4 +18,4 @@ GitPython~=2.1
lxml~=4.2
pillow~=5.3
pyScss~=1.3
redis~=3.0
redis==2.10.6