mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(rpc): simplify json generation complexity
This simply decouples depends and relations population into their own helper functions. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
9464de108f
commit
b3b31394e8
1 changed files with 33 additions and 27 deletions
|
@ -1,5 +1,5 @@
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
from sqlalchemy import and_
|
from sqlalchemy import and_
|
||||||
|
|
||||||
|
@ -95,6 +95,36 @@ class RPC:
|
||||||
raise RPCError(
|
raise RPCError(
|
||||||
f"Request type '{self.type}' is not yet implemented.")
|
f"Request type '{self.type}' is not yet implemented.")
|
||||||
|
|
||||||
|
def _update_json_depends(self, package: models.Package,
|
||||||
|
data: Dict[str, Any]):
|
||||||
|
# Walk through all related PackageDependencies and produce
|
||||||
|
# the appropriate dict entries.
|
||||||
|
depends = package.package_dependencies
|
||||||
|
for dep in depends:
|
||||||
|
if dep.DepTypeID in DEP_TYPES:
|
||||||
|
key = DEP_TYPES.get(dep.DepTypeID)
|
||||||
|
|
||||||
|
display = dep.DepName
|
||||||
|
if dep.DepCondition:
|
||||||
|
display += dep.DepCondition
|
||||||
|
|
||||||
|
data[key].append(display)
|
||||||
|
|
||||||
|
def _update_json_relations(self, package: models.Package,
|
||||||
|
data: Dict[str, Any]):
|
||||||
|
# Walk through all related PackageRelations and produce
|
||||||
|
# the appropriate dict entries.
|
||||||
|
relations = package.package_relations
|
||||||
|
for rel in relations:
|
||||||
|
if rel.RelTypeID in REL_TYPES:
|
||||||
|
key = REL_TYPES.get(rel.RelTypeID)
|
||||||
|
|
||||||
|
display = rel.RelName
|
||||||
|
if rel.RelCondition:
|
||||||
|
display += rel.RelCondition
|
||||||
|
|
||||||
|
data[key].append(display)
|
||||||
|
|
||||||
def _get_json_data(self, package: models.Package):
|
def _get_json_data(self, package: models.Package):
|
||||||
""" Produce dictionary data of one Package that can be JSON-serialized.
|
""" Produce dictionary data of one Package that can be JSON-serialized.
|
||||||
|
|
||||||
|
@ -137,32 +167,8 @@ class RPC:
|
||||||
# We do have a maintainer: set the Maintainer key.
|
# We do have a maintainer: set the Maintainer key.
|
||||||
data["Maintainer"] = package.PackageBase.Maintainer.Username
|
data["Maintainer"] = package.PackageBase.Maintainer.Username
|
||||||
|
|
||||||
# Walk through all related PackageDependencies and produce
|
self._update_json_depends(package, data)
|
||||||
# the appropriate dict entries.
|
self._update_json_relations(package, data)
|
||||||
if depends := package.package_dependencies:
|
|
||||||
for dep in depends:
|
|
||||||
if dep.DepTypeID in DEP_TYPES:
|
|
||||||
key = DEP_TYPES.get(dep.DepTypeID)
|
|
||||||
|
|
||||||
display = dep.DepName
|
|
||||||
if dep.DepCondition:
|
|
||||||
display += dep.DepCondition
|
|
||||||
|
|
||||||
data[key].append(display)
|
|
||||||
|
|
||||||
# Walk through all related PackageRelations and produce
|
|
||||||
# the appropriate dict entries.
|
|
||||||
if relations := package.package_relations:
|
|
||||||
for rel in relations:
|
|
||||||
if rel.RelTypeID in REL_TYPES:
|
|
||||||
key = REL_TYPES.get(rel.RelTypeID)
|
|
||||||
|
|
||||||
display = rel.RelName
|
|
||||||
if rel.RelCondition:
|
|
||||||
display += rel.RelCondition
|
|
||||||
|
|
||||||
data[key].append(display)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _handle_multiinfo_type(self, args: List[str] = []):
|
def _handle_multiinfo_type(self, args: List[str] = []):
|
||||||
|
|
Loading…
Add table
Reference in a new issue