예제 #1
0
파일: modules.py 프로젝트: marmarek/lorax
def modules_cmd(opts):
    """Process modules commands

    :param opts: Cmdline arguments
    :type opts: argparse.Namespace
    :returns: Value to return from sys.exit()
    :rtype: int
    """
    if opts.args[1] == "help" or opts.args[1] == "--help":
        print(modules_help)
        return 0
    elif 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_unlimited(opts.socket, api_route)
    (rc, exit_now) = handle_api_result(result, opts.json)
    if exit_now:
        return rc

    # "list" should output a plain list of identifiers, one per line.
    print("\n".join(r["name"] for r in result["modules"]))

    return rc
예제 #2
0
def blueprints_changes(socket_path, api_version, args, show_json=False):
    """Display the changes for each of the blueprints

    :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

    blueprints changes <blueprint,...>     Display the changes for each blueprint.
    """
    def changes_total_fn(data):
        """Return the maximum number of possible changes"""

        # Each blueprint can have a different total, return the largest one
        return max([c["total"] for c in data["blueprints"]])

    api_route = client.api_url(api_version, "/blueprints/changes/%s" % (",".join(argify(args))))
    result = client.get_url_json_unlimited(socket_path, api_route, total_fn=changes_total_fn)
    (rc, exit_now) = handle_api_result(result, show_json)
    if exit_now:
        return rc

    for blueprint in result["blueprints"]:
        print(blueprint["name"])
        for change in blueprint["changes"]:
            prettyCommitDetails(change)

    return rc
예제 #3
0
파일: projects.py 프로젝트: yuvalturg/lorax
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_unlimited(socket_path, api_route)
    (rc, exit_now) = handle_api_result(result, show_json)
    if exit_now:
        return rc

    for proj in result["projects"]:
        for k in [
                field
                for field in ("name", "summary", "homepage", "description")
                if proj[field]
        ]:
            print("%s: %s" %
                  (k.title(),
                   textwrap.fill(proj[k], subsequent_indent=" " *
                                 (len(k) + 2))))
        print("\n\n")

    return rc
예제 #4
0
def blueprints_list(socket_path, api_version, args, show_json=False):
    """Output the list of available blueprints

    :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

    blueprints list
    """
    api_route = client.api_url(api_version, "/blueprints/list")
    result = client.get_url_json_unlimited(socket_path, api_route)
    (rc, exit_now) = handle_api_result(result, show_json)
    if exit_now:
        return rc

    # "list" should output a plain list of identifiers, one per line.
    print("\n".join(result["blueprints"]))

    return rc