diff --git a/src/pylorax/api/projects.py b/src/pylorax/api/projects.py index 7db72427..42806096 100644 --- a/src/pylorax/api/projects.py +++ b/src/pylorax/api/projects.py @@ -17,6 +17,29 @@ import logging 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): """Extract the details from a YumAvailablePackageSqlite object""" @@ -27,6 +50,29 @@ def yaps_to_project(yaps): "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): """Return a list of projects @@ -35,37 +81,42 @@ def projects_list(yb): :returns: List of project information :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) return sorted(map(yaps_to_project, ybl.available), key=lambda p: p["name"].lower()) -def projects_info(yb, project_name): - """Return details about a specific project +def projects_info(yb, project_names): + """Return details about specific projects :param yb: yum base object :type yb: YumBase - :param project_name: Name of the project to get info about - :type project_name: str + :param project_names: List of names of projects to get info about + :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 :param yb: yum base object :type yb: YumBase - :param projects: The projects to find the dependencies for - :type projects: List of Strings + :param project_names: The projects to find the dependencies for + :type project_names: List of Strings :returns: ... :rtype: ... """ pass -def modules_list(yb, offset, limit): +def modules_list(yb): """Return a list of modules :param yb: yum base object @@ -83,12 +134,12 @@ def modules_list(yb, offset, limit): pass -def modules_info(yb, module_name): +def modules_info(yb, module_names): """Return details about a module, including dependencies :param yb: yum base object :type yb: YumBase - :param module_name: Name of the module to get info about - :type module_name: str + :param module_names: Names of the modules to get info about + :type module_names: str """ pass diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 30c36841..c5a9bec5 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -24,7 +24,7 @@ from pykickstart.parser import KickstartParser from pykickstart.version import makeVersion, RHEL7 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 recipe_from_dict, recipe_from_toml, commit_recipe, delete_recipe, revert_recipe from pylorax.api.recipes import tag_recipe_commit, recipe_diff @@ -296,3 +296,12 @@ def v0_api(api): projects = take_limits(available, offset, limit) return jsonify(projects=projects, offset=offset, limit=limit, total=len(available)) + + @api.route("/api/v0/projects/info/") + @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)