Server IP : 195.201.23.43 / Your IP : 3.140.184.21 Web Server : Apache System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64 User : kdecoratie ( 1041) PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib/python3/dist-packages/uaclient/cli/ |
Upload File : |
import json import sys from collections import OrderedDict from typing import Any, Optional # noqa: F401 from uaclient import exceptions, messages from uaclient.api import AbstractProgress from uaclient.api.api import call_api class CLIAPIProgress(AbstractProgress): def progress( self, *, total_steps: int, done_steps: int, previous_step_message: Optional[str], current_step_message: Optional[str] ): d = OrderedDict() # type: OrderedDict[str, Any] d["total_steps"] = total_steps d["done_steps"] = done_steps d["previous_step_message"] = previous_step_message d["current_step_message"] = current_step_message print(json.dumps(d)) def action_api(args, *, cfg, **kwargs): if args.options and args.data: raise exceptions.CLIAPIOptionsXORData() if args.data and args.data == "-": if not sys.stdin.isatty(): args.data = sys.stdin.read() if args.show_progress: progress = CLIAPIProgress() else: progress = None result = call_api( args.endpoint_path, args.options, args.data, cfg, progress ) print(result.to_json()) return 0 if result.result == "success" else 1 def add_parser(subparsers, cfg): """Build or extend an arg parser for the api subcommand.""" parser = subparsers.add_parser("api", help=messages.CLI_ROOT_API) parser.prog = "api" parser.description = messages.CLI_API_DESC parser.add_argument( "endpoint_path", metavar="endpoint", help=messages.CLI_API_ENDPOINT ) parser.add_argument( "--show-progress", action="store_true", help=messages.CLI_API_SHOW_PROGRESS, ) parser.add_argument( "--args", dest="options", default=[], nargs="*", help=messages.CLI_API_ARGS, ) parser.add_argument( "--data", dest="data", default="", help=messages.CLI_API_DATA ) parser.set_defaults(action=action_api) return parserPrivate