Add /projects/info route
Elements that have no match in yum (metadata) are set to empty dicts.
This commit is contained in:
parent
0819e97646
commit
99140b98b9
@ -17,6 +17,29 @@
|
|||||||
import logging
|
import logging
|
||||||
log = logging.getLogger("lorax-composer")
|
log = logging.getLogger("lorax-composer")
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
TIME_FORMAT = "%Y-%m-%dT%H:%M:%S"
|
||||||
|
|
||||||
|
def api_time(t):
|
||||||
|
"""Convert time since epoch to a string"""
|
||||||
|
return time.strftime(TIME_FORMAT, time.localtime(t))
|
||||||
|
|
||||||
|
|
||||||
|
def api_changelog(changelog):
|
||||||
|
"""Convert the changelog to a string
|
||||||
|
|
||||||
|
:param changelog: A list of time, author, string tuples.
|
||||||
|
:type changelog: tuple
|
||||||
|
:returns: The most recent changelog text
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
entry = changelog[0][2]
|
||||||
|
except IndexError:
|
||||||
|
entry = ""
|
||||||
|
return entry
|
||||||
|
|
||||||
|
|
||||||
def yaps_to_project(yaps):
|
def yaps_to_project(yaps):
|
||||||
"""Extract the details from a YumAvailablePackageSqlite object"""
|
"""Extract the details from a YumAvailablePackageSqlite object"""
|
||||||
@ -27,6 +50,29 @@ def yaps_to_project(yaps):
|
|||||||
"upstream_vcs": "UPSTREAM_VCS"}
|
"upstream_vcs": "UPSTREAM_VCS"}
|
||||||
|
|
||||||
|
|
||||||
|
def yaps_to_project_info(yaps):
|
||||||
|
"""Extract the details from a YumAvailablePackageSqlite object"""
|
||||||
|
build = {"epoch": yaps.epoch,
|
||||||
|
"release": yaps.release,
|
||||||
|
"arch": yaps.arch,
|
||||||
|
"build_time": api_time(yaps.buildtime),
|
||||||
|
"changelog": api_changelog(yaps.returnChangelog()),
|
||||||
|
"build_config_ref": "BUILD_CONFIG_REF",
|
||||||
|
"build_env_ref": "BUILD_ENV_REF",
|
||||||
|
"metadata": {},
|
||||||
|
"source": {"license": yaps.license,
|
||||||
|
"version": yaps.version,
|
||||||
|
"source_ref": "SOURCE_REF",
|
||||||
|
"metadata": {}}}
|
||||||
|
|
||||||
|
return {"name": yaps.name,
|
||||||
|
"summary": yaps.summary,
|
||||||
|
"description": yaps.description,
|
||||||
|
"homepage": yaps.url,
|
||||||
|
"upstream_vcs": "UPSTREAM_VCS",
|
||||||
|
"builds": [build]}
|
||||||
|
|
||||||
|
|
||||||
def projects_list(yb):
|
def projects_list(yb):
|
||||||
"""Return a list of projects
|
"""Return a list of projects
|
||||||
|
|
||||||
@ -35,37 +81,42 @@ def projects_list(yb):
|
|||||||
:returns: List of project information
|
:returns: List of project information
|
||||||
:rtype: List of Dicts
|
:rtype: List of Dicts
|
||||||
|
|
||||||
name, summary, dfescription, homepage, upstream_vcs
|
Returns a list of dicts with these fields:
|
||||||
|
name, summary, description, homepage, upstream_vcs
|
||||||
"""
|
"""
|
||||||
ybl = yb.doPackageLists(pkgnarrow="available", showdups=False)
|
ybl = yb.doPackageLists(pkgnarrow="available", showdups=False)
|
||||||
return sorted(map(yaps_to_project, ybl.available), key=lambda p: p["name"].lower())
|
return sorted(map(yaps_to_project, ybl.available), key=lambda p: p["name"].lower())
|
||||||
|
|
||||||
|
|
||||||
def projects_info(yb, project_name):
|
def projects_info(yb, project_names):
|
||||||
"""Return details about a specific project
|
"""Return details about specific projects
|
||||||
|
|
||||||
:param yb: yum base object
|
:param yb: yum base object
|
||||||
:type yb: YumBase
|
:type yb: YumBase
|
||||||
:param project_name: Name of the project to get info about
|
:param project_names: List of names of projects to get info about
|
||||||
:type project_name: str
|
:type project_names: str
|
||||||
|
:returns: List of project details
|
||||||
|
:rtype: List of Dicts
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
ybl = yb.doPackageLists(pkgnarrow="available", patterns=project_names, showdups=False)
|
||||||
|
return sorted(map(yaps_to_project_info, ybl.available), key=lambda p: p["name"].lower())
|
||||||
|
|
||||||
|
|
||||||
def projects_depsolve(yb, projects):
|
def projects_depsolve(yb, project_names):
|
||||||
"""Return the dependencies for a list of projects
|
"""Return the dependencies for a list of projects
|
||||||
|
|
||||||
:param yb: yum base object
|
:param yb: yum base object
|
||||||
:type yb: YumBase
|
:type yb: YumBase
|
||||||
:param projects: The projects to find the dependencies for
|
:param project_names: The projects to find the dependencies for
|
||||||
:type projects: List of Strings
|
:type project_names: List of Strings
|
||||||
:returns: ...
|
:returns: ...
|
||||||
:rtype: ...
|
:rtype: ...
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def modules_list(yb, offset, limit):
|
def modules_list(yb):
|
||||||
"""Return a list of modules
|
"""Return a list of modules
|
||||||
|
|
||||||
:param yb: yum base object
|
:param yb: yum base object
|
||||||
@ -83,12 +134,12 @@ def modules_list(yb, offset, limit):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def modules_info(yb, module_name):
|
def modules_info(yb, module_names):
|
||||||
"""Return details about a module, including dependencies
|
"""Return details about a module, including dependencies
|
||||||
|
|
||||||
:param yb: yum base object
|
:param yb: yum base object
|
||||||
:type yb: YumBase
|
:type yb: YumBase
|
||||||
:param module_name: Name of the module to get info about
|
:param module_names: Names of the modules to get info about
|
||||||
:type module_name: str
|
:type module_names: str
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
@ -24,7 +24,7 @@ from pykickstart.parser import KickstartParser
|
|||||||
from pykickstart.version import makeVersion, RHEL7
|
from pykickstart.version import makeVersion, RHEL7
|
||||||
|
|
||||||
from pylorax.api.crossdomain import crossdomain
|
from pylorax.api.crossdomain import crossdomain
|
||||||
from pylorax.api.projects import projects_list
|
from pylorax.api.projects import projects_list, projects_info
|
||||||
from pylorax.api.recipes import list_branch_files, read_recipe_commit, recipe_filename, list_commits
|
from pylorax.api.recipes import list_branch_files, read_recipe_commit, recipe_filename, list_commits
|
||||||
from pylorax.api.recipes import recipe_from_dict, recipe_from_toml, commit_recipe, delete_recipe, revert_recipe
|
from pylorax.api.recipes import recipe_from_dict, recipe_from_toml, commit_recipe, delete_recipe, revert_recipe
|
||||||
from pylorax.api.recipes import tag_recipe_commit, recipe_diff
|
from pylorax.api.recipes import tag_recipe_commit, recipe_diff
|
||||||
@ -296,3 +296,12 @@ def v0_api(api):
|
|||||||
projects = take_limits(available, offset, limit)
|
projects = take_limits(available, offset, limit)
|
||||||
|
|
||||||
return jsonify(projects=projects, offset=offset, limit=limit, total=len(available))
|
return jsonify(projects=projects, offset=offset, limit=limit, total=len(available))
|
||||||
|
|
||||||
|
@api.route("/api/v0/projects/info/<project_names>")
|
||||||
|
@crossdomain(origin="*")
|
||||||
|
def v0_projects_info(project_names):
|
||||||
|
"""Return detailed information about the listed projects"""
|
||||||
|
with api.config["YUMLOCK"].lock:
|
||||||
|
projects = projects_info(api.config["YUMLOCK"].yb, project_names.split(","))
|
||||||
|
|
||||||
|
return jsonify(projects=projects)
|
||||||
|
Loading…
Reference in New Issue
Block a user