From 55c0c188ec0e453bb58b7c9dc52114f26ad22d15 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Mon, 8 Jul 2024 15:30:58 -0400 Subject: [PATCH] action --profile option --- ckanapi/cli/action.py | 14 ++++++++++++-- ckanapi/cli/main.py | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ckanapi/cli/action.py b/ckanapi/cli/action.py index 8c2b335..ceb5eaa 100644 --- a/ckanapi/cli/action.py +++ b/ckanapi/cli/action.py @@ -56,8 +56,18 @@ def action(ckan, arguments, stdin=None): raise CLIError("argument not in the form KEY=STRING, " "KEY:JSON or KEY@FILE %r" % kv) - result = ckan.call_action(arguments['ACTION_NAME'], action_args, - files=file_args, requests_kwargs=requests_kwargs) + def call(): + return ckan.call_action(arguments['ACTION_NAME'], action_args, + files=file_args, + requests_kwargs=requests_kwargs) + + if arguments['--profile']: + from cProfile import Profile + with Profile() as pr: + result = call() + pr.dump_stats(arguments['--profile']) + else: + result = call() if arguments['--output-jsonl']: if isinstance(result, list): diff --git a/ckanapi/cli/main.py b/ckanapi/cli/main.py index ac22e03..04ce7f5 100644 --- a/ckanapi/cli/main.py +++ b/ckanapi/cli/main.py @@ -3,7 +3,7 @@ Usage: ckanapi action ACTION_NAME [(KEY=STRING | KEY:JSON | KEY@FILE ) ... | -i | -I JSON_INPUT] - [-j | -J] + [-j | -J] [-P PROFILE ] [[-c CONFIG] [-u USER] | -r SITE_URL [-a APIKEY] [-g] [--insecure]] ckanapi batch [-I JSONL_INPUT] [-s START] [-m MAX] [--local-files] [-p PROCESSES] [-l LOG_FILE] [-qwz] @@ -62,6 +62,8 @@ -o --update-only update existing records, don't create new records -O --output=JSONL_OUTPUT output to json lines file instead of stdout -p --processes=PROCESSES set the number of worker processes [default: 1] + -P --profile=PROFILE run action with cProfile and output to PROFILE + only local actions (no -r) will show internals -q --quiet don't display progress messages -r --remote=URL URL of CKAN server for remote actions -R --resource-views export resource views information along with