Add filtering and glob support to /modules/list route
This commit is contained in:
parent
53d6be4703
commit
a914253102
@ -202,7 +202,7 @@ def projects_depsolve(yb, project_names):
|
||||
return sorted(map(tm_to_dep, yb.tsInfo.installed + yb.tsInfo.depinstalled), key=lambda p: p["name"].lower())
|
||||
|
||||
|
||||
def modules_list(yb):
|
||||
def modules_list(yb, module_names):
|
||||
"""Return a list of modules
|
||||
|
||||
:param yb: yum base object
|
||||
@ -218,7 +218,7 @@ def modules_list(yb):
|
||||
and sets the type to "rpm"
|
||||
"""
|
||||
try:
|
||||
ybl = yb.doPackageLists(pkgnarrow="available", showdups=False)
|
||||
ybl = yb.doPackageLists(pkgnarrow="available", patterns=module_names, showdups=False)
|
||||
except YumBaseError as e:
|
||||
raise ProjectsError("There was a problem listing modules: %s" % str(e))
|
||||
return sorted(map(yaps_to_module, ybl.available), key=lambda p: p["name"].lower())
|
||||
|
@ -443,18 +443,22 @@ def v0_api(api):
|
||||
return jsonify(projects=deps)
|
||||
|
||||
@api.route("/api/v0/modules/list")
|
||||
@api.route("/api/v0/modules/list/<module_names>")
|
||||
@crossdomain(origin="*")
|
||||
def v0_modules_list():
|
||||
"""List all of the available modules"""
|
||||
def v0_modules_list(module_names=None):
|
||||
"""List available modules, filtering by module_names"""
|
||||
try:
|
||||
limit = int(request.args.get("limit", "20"))
|
||||
offset = int(request.args.get("offset", "0"))
|
||||
except ValueError as e:
|
||||
return jsonify(error={"msg":str(e)}), 400
|
||||
|
||||
if module_names:
|
||||
module_names = module_names.split(",")
|
||||
|
||||
try:
|
||||
with api.config["YUMLOCK"].lock:
|
||||
available = modules_list(api.config["YUMLOCK"].yb)
|
||||
available = modules_list(api.config["YUMLOCK"].yb, module_names)
|
||||
except ProjectsError as e:
|
||||
log.error("(v0_modules_list) %s", str(e))
|
||||
return jsonify(error={"msg":str(e)}), 400
|
||||
|
@ -147,11 +147,14 @@ class ProjectsTest(unittest.TestCase):
|
||||
projects_depsolve(self.yb, ["nada-package"])
|
||||
|
||||
def test_modules_list(self):
|
||||
modules = modules_list(self.yb)
|
||||
modules = modules_list(self.yb, None)
|
||||
|
||||
self.assertEqual(len(modules) > 10, True)
|
||||
self.assertEqual(modules[0]["group_type"], "rpm")
|
||||
|
||||
modules = modules_list(self.yb, ["g*"])
|
||||
self.assertEqual(modules[0]["name"].startswith("g"), True)
|
||||
|
||||
def test_modules_info(self):
|
||||
modules = modules_info(self.yb, ["bash"])
|
||||
|
||||
|
@ -419,6 +419,14 @@ class ServerTestCase(unittest.TestCase):
|
||||
self.assertEqual(len(modules) > 10, True)
|
||||
self.assertEqual(modules[0]["group_type"], "rpm")
|
||||
|
||||
resp = self.server.get("/api/v0/modules/list/d*")
|
||||
data = json.loads(resp.data)
|
||||
self.assertNotEqual(data, None)
|
||||
print(data)
|
||||
modules = data.get("modules")
|
||||
self.assertEqual(len(modules) > 0, True)
|
||||
self.assertEqual(modules[0]["name"].startswith("d"), True)
|
||||
|
||||
def test_modules_info(self):
|
||||
"""Test /api/v0/modules/info"""
|
||||
resp = self.server.get("/api/v0/modules/info/bash")
|
||||
|
Loading…
Reference in New Issue
Block a user