def sources_add(socket_path, api_version, args, show_json=False): """Add or change a source :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 sources add <source.toml> """ api_route = client.api_url(api_version, "/projects/source/new") rval = 0 for source in argify(args): if not os.path.exists(source): log.error("Missing source file: %s", source) continue source_toml = open(source, "r").read() result = client.post_url_toml(socket_path, api_route, source_toml) if handle_api_result(result, show_json): rval = 1 return rval
def blueprints_freeze_save(socket_path, api_version, args, show_json=False): """Save the frozen blueprint to a TOML file :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 freeze save <blueprint,...> Save the frozen blueprint to a file, <blueprint-name>.frozen.toml. """ if len(args) == 0: log.error("freeze save is missing the blueprint name") return 1 for blueprint in argify(args): api_route = client.api_url( api_version, "/blueprints/freeze/%s?format=toml" % blueprint) blueprint_toml = client.get_url_raw(socket_path, api_route) open(frozen_toml_filename(blueprint), "w").write(blueprint_toml) return 0
def blueprints_workspace(socket_path, api_version, args, show_json=False): """Push the blueprint TOML to the temporary workspace storage :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 workspace <blueprint> Push the blueprint TOML to the temporary workspace storage. """ api_route = client.api_url(api_version, "/blueprints/workspace") rval = 0 for blueprint in argify(args): if not os.path.exists(blueprint): log.error("Missing blueprint file: %s", blueprint) continue blueprint_toml = open(blueprint, "r").read() result = client.post_url_toml(socket_path, api_route, blueprint_toml) if show_json: print(json.dumps(result, indent=4)) for err in result.get("errors", []): log.error(err) # Any errors results in returning a 1, but we continue with the rest first if not result.get("status", False): rval = 1 return rval
def blueprints_push(socket_path, api_version, args, show_json=False): """Push a blueprint TOML file to the server, updating the blueprint :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 push <blueprint> Push a blueprint TOML file to the server. """ api_route = client.api_url(api_version, "/blueprints/new") rval = 0 for blueprint in argify(args): if not os.path.exists(blueprint): log.error("Missing blueprint file: %s", blueprint) continue blueprint_toml = open(blueprint, "r").read() result = client.post_url_toml(socket_path, api_route, blueprint_toml) if handle_api_result(result, show_json): rval = 1 return rval
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. """ api_route = client.api_url( api_version, "/blueprints/changes/%s" % (",".join(argify(args)))) result = client.get_url_json(socket_path, api_route) if show_json: print(json.dumps(result, indent=4)) return 0 for blueprint in result["blueprints"]: print(blueprint["name"]) for change in blueprint["changes"]: prettyCommitDetails(change) return 0
def blueprints_depsolve(socket_path, api_version, args, show_json=False): """Display the packages needed to install the blueprint :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 depsolve <blueprint,...> Display the packages needed to install the blueprint. """ api_route = client.api_url( api_version, "/blueprints/depsolve/%s" % (",".join(argify(args)))) result = client.get_url_json(socket_path, api_route) if show_json: print(json.dumps(result, indent=4)) return 0 for blueprint in result["blueprints"]: if blueprint["blueprint"].get("version", ""): print("blueprint: %s v%s" % (blueprint["blueprint"]["name"], blueprint["blueprint"]["version"])) else: print("blueprint: %s" % (blueprint["blueprint"]["name"])) for dep in blueprint["dependencies"]: print(" " + packageNEVRA(dep)) return 0
def blueprints_workspace(socket_path, api_version, args, show_json=False): """Push the blueprint TOML to the temporary workspace storage :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 workspace <blueprint> Push the blueprint TOML to the temporary workspace storage. """ api_route = client.api_url(api_version, "/blueprints/workspace") rval = 0 for blueprint in argify(args): if not os.path.exists(blueprint): log.error("Missing blueprint file: %s", blueprint) continue with open(blueprint, "r") as f: blueprint_toml = f.read() result = client.post_url_toml(socket_path, api_route, blueprint_toml) if handle_api_result(result, show_json)[0]: rval = 1 return rval
def compose_delete(socket_path, api_version, args, show_json=False, testmode=0, api=None): """Delete a finished compose's results :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 :param testmode: unused in this function :type testmode: int compose delete <uuid,...> Delete the listed compose results. It will only delete results for composes that have finished or failed, not a running compose. """ if len(args) == 0: log.error("delete is missing the compose build id") return 1 api_route = client.api_url(api_version, "/compose/delete/%s" % (",".join(argify(args)))) result = client.delete_url_json(socket_path, api_route) return handle_api_result(result, show_json)[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
def blueprints_freeze(socket_path, api_version, args, show_json=False): """Handle the blueprints freeze commands :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 freeze <blueprint,...> Display the frozen blueprint's modules and packages. blueprints freeze show <blueprint,...> Display the frozen blueprint in TOML format. blueprints freeze save <blueprint,...> Save the frozen blueprint to a file, <blueprint-name>.frozen.toml. """ if args[0] == "show": return blueprints_freeze_show(socket_path, api_version, args[1:], show_json) elif args[0] == "save": return blueprints_freeze_save(socket_path, api_version, args[1:], show_json) if len(args) == 0: log.error("freeze is missing the blueprint name") return 1 api_route = client.api_url( api_version, "/blueprints/freeze/%s" % (",".join(argify(args)))) result = client.get_url_json(socket_path, api_route) if show_json: print(json.dumps(result, indent=4)) else: for entry in result["blueprints"]: blueprint = entry["blueprint"] if blueprint.get("version", ""): print("blueprint: %s v%s" % (blueprint["name"], blueprint["version"])) else: print("blueprint: %s" % (blueprint["name"])) for m in blueprint["modules"]: print(" %s-%s" % (m["name"], m["version"])) for p in blueprint["packages"]: print(" %s-%s" % (p["name"], p["version"])) # Print any errors for err in result.get("errors", []): log.error(err) # Return a 1 if there are any errors if result.get("errors", []): return 1 else: return 0
def blueprints_show(socket_path, api_version, args, show_json=False): """Show the blueprints, in TOML format :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 show <blueprint,...> Display the blueprint in TOML format. Multiple blueprints will be separated by \n\n """ for blueprint in argify(args): api_route = client.api_url(api_version, "/blueprints/info/%s?format=toml" % blueprint) print(client.get_url_raw(socket_path, api_route) + "\n\n") return 0
def blueprints_save(socket_path, api_version, args, show_json=False): """Save the blueprint to a TOML file :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 save <blueprint,...> Save the blueprint to a file, <blueprint-name>.toml """ for blueprint in argify(args): api_route = client.api_url(api_version, "/blueprints/info/%s?format=toml" % blueprint) blueprint_toml = client.get_url_raw(socket_path, api_route) with open(toml_filename(blueprint), "w") as f: f.write(blueprint_toml) return 0
def blueprints_freeze_show(socket_path, api_version, args, show_json=False): """Show the frozen blueprint in TOML format :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 freeze show <blueprint,...> Display the frozen blueprint in TOML format. """ if len(args) == 0: log.error("freeze show is missing the blueprint name") return 1 for blueprint in argify(args): api_route = client.api_url(api_version, "/blueprints/freeze/%s?format=toml" % blueprint) print(client.get_url_raw(socket_path, api_route)) return 0
def test_argify(self): """Convert an optionally comma-separated cmdline into a list of args""" self.assertEqual(argify(["one,two", "three", ",four", ",five,"]), ["one", "two", "three", "four", "five"])