Add support for modules list, projects list, and projects info
This commit is contained in:
parent
d2f784e5da
commit
9ba24f305d
@ -50,6 +50,7 @@ recipes list List the names of the available recipes.
|
|||||||
workspace <recipe> Push the recipe TOML to the temporary workspace storage.
|
workspace <recipe> Push the recipe TOML to the temporary workspace storage.
|
||||||
modules list List the available modules.
|
modules list List the available modules.
|
||||||
projects list List the available projects.
|
projects list List the available projects.
|
||||||
|
projects info <project,...> Show details about the listed projects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_parser():
|
def get_parser():
|
||||||
|
@ -14,6 +14,12 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger("composer-cli")
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from composer import http_client as client
|
||||||
|
|
||||||
def modules_cmd(opts):
|
def modules_cmd(opts):
|
||||||
"""Process modules commands
|
"""Process modules commands
|
||||||
@ -23,4 +29,16 @@ def modules_cmd(opts):
|
|||||||
:returns: Value to return from sys.exit()
|
:returns: Value to return from sys.exit()
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
return 1
|
if opts.args[1] != "list":
|
||||||
|
log.error("Unknown modules command: %s", opts.args[1])
|
||||||
|
return 1
|
||||||
|
|
||||||
|
api_route = client.api_url(opts.api_version, "/modules/list")
|
||||||
|
result = client.get_url_json(opts.socket, api_route)
|
||||||
|
if opts.json:
|
||||||
|
print(json.dumps(result, indent=4))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
print("Modules:\n" + "\n".join([" "+r["name"] for r in result["modules"]]))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
@ -14,6 +14,13 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger("composer-cli")
|
||||||
|
|
||||||
|
import json
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
from composer import http_client as client
|
||||||
|
|
||||||
def projects_cmd(opts):
|
def projects_cmd(opts):
|
||||||
"""Process projects commands
|
"""Process projects commands
|
||||||
@ -23,4 +30,73 @@ def projects_cmd(opts):
|
|||||||
:returns: Value to return from sys.exit()
|
:returns: Value to return from sys.exit()
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
return 1
|
cmd_map = {
|
||||||
|
"list": projects_list,
|
||||||
|
"info": projects_info,
|
||||||
|
}
|
||||||
|
return cmd_map[opts.args[1]](opts.socket, opts.api_version, opts.args[2:], opts.json)
|
||||||
|
|
||||||
|
def projects_list(socket_path, api_version, args, show_json=False):
|
||||||
|
"""Output the list of available projects
|
||||||
|
|
||||||
|
:param socket_path: Path to the Unix socket to use for API communication
|
||||||
|
:type socket_path: str
|
||||||
|
:param api_version: Version of the API to talk to. eg. "0"
|
||||||
|
:type api_version: str
|
||||||
|
:param args: List of remaining arguments from the cmdline
|
||||||
|
:type args: list of str
|
||||||
|
:param show_json: Set to True to show the JSON output instead of the human readable output
|
||||||
|
:type show_json: bool
|
||||||
|
|
||||||
|
projects list
|
||||||
|
"""
|
||||||
|
api_route = client.api_url(api_version, "/projects/list")
|
||||||
|
result = client.get_url_json(socket_path, api_route)
|
||||||
|
if show_json:
|
||||||
|
print(json.dumps(result, indent=4))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
for proj in result["projects"]:
|
||||||
|
for k in ["name", "summary", "homepage", "description"]:
|
||||||
|
print("%s: %s" % (k.title(), textwrap.fill(proj[k], subsequent_indent=" " * (len(k)+2))))
|
||||||
|
print("\n\n")
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def projects_info(socket_path, api_version, args, show_json=False):
|
||||||
|
"""Output info on a list of projects
|
||||||
|
|
||||||
|
:param socket_path: Path to the Unix socket to use for API communication
|
||||||
|
:type socket_path: str
|
||||||
|
:param api_version: Version of the API to talk to. eg. "0"
|
||||||
|
:type api_version: str
|
||||||
|
:param args: List of remaining arguments from the cmdline
|
||||||
|
:type args: list of str
|
||||||
|
:param show_json: Set to True to show the JSON output instead of the human readable output
|
||||||
|
:type show_json: bool
|
||||||
|
|
||||||
|
projects info <project,...>
|
||||||
|
"""
|
||||||
|
if len(args) == 0:
|
||||||
|
log.error("projects info is missing the packages")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
api_route = client.api_url(api_version, "/projects/info/%s" % ",".join(args))
|
||||||
|
result = client.get_url_json(socket_path, api_route)
|
||||||
|
if show_json:
|
||||||
|
print(json.dumps(result, indent=4))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
for proj in result["projects"]:
|
||||||
|
for k in ["name", "summary", "homepage", "description"]:
|
||||||
|
print("%s: %s" % (k.title(), textwrap.fill(proj[k], subsequent_indent=" " * (len(k)+2))))
|
||||||
|
print("Builds: ")
|
||||||
|
for build in proj["builds"]:
|
||||||
|
print(" %s%s-%s.%s at %s for %s" % ("" if not build["epoch"] else build["epoch"] + ":",
|
||||||
|
build["source"]["version"],
|
||||||
|
build["release"],
|
||||||
|
build["arch"],
|
||||||
|
build["build_time"],
|
||||||
|
build["changelog"]))
|
||||||
|
print("")
|
||||||
|
return 0
|
||||||
|
Loading…
Reference in New Issue
Block a user