diff --git a/changes/7402.feature b/changes/7402.feature new file mode 100644 index 00000000000..43caf845e7f --- /dev/null +++ b/changes/7402.feature @@ -0,0 +1 @@ +update documenatation for CKAN SHELL command. diff --git a/doc/maintaining/cli.rst b/doc/maintaining/cli.rst index 0e1600f35f1..41f523df662 100644 --- a/doc/maintaining/cli.rst +++ b/doc/maintaining/cli.rst @@ -93,6 +93,83 @@ with the ``--help`` option, for example: ckan -c |ckan.ini| user --help +------------------------------- +CLI command: ckan shell +------------------------------- +The main goal to execute a ckan shell command is IPython session with the application loaded for easy debugging and dynamic coding. + +There are three variables already populated into the namespace of the shell: + +• **app** containing the Flask application +• **config** containing the CKAN config dictrionary +• **model** module to access to the database using SQLAlchemy syntax + +**command:** + +.. parsed-literal:: + $ ckan shell + +Example 1: +================ + +.. parsed-literal:: + + $ ckan shell + Python 3.9.13 (main, Dec 11 2022, 15:23:12) + Type 'copyright', 'credits' or 'license' for more information + + **In [1]:** model.User.all() + **Out[1]:** + [] + +.. parsed-literal:: + + **In [2]:** from ckan.logic.action.get import package_show + + **In [3]:** package_show({"model": model}, {"id": "api-package-1"}) + **Out[3]:** + {'author': None, + 'author_email': None, + 'creator_user_id': 'f0c04c11-4369-4cf1-9da4-69d9aae06a2e', + 'id': '922f3a91-c9ed-4e19-a722-366671b7d72c', + 'isopen': False, + 'license_id': None, + 'license_title': None, + 'maintainer': None, + 'maintainer_email': None, + 'metadata_created': '2022-06-16T14:13:37.736125', + 'metadata_modified': '2022-06-16T14:20:19.639665', + 'name': 'api-package-1', + 'notes': 'Update from API:10000', + 'num_resources': 0, + 'num_tags': 0, + 'organization': None, + 'owner_org': None, + 'private': False, + 'state': 'active', + 'title': 'api-package-1', + 'type': 'dataset', + 'url': None, + 'version': None, + 'resources': [], + 'tags': [], + 'extras': [], + 'groups': [], + 'relationships_as_subject': [], + 'relationships_as_object': []} + + +Example 2: +================ + +.. parsed-literal:: + + **In [7]:** from ckanext.activity.logic import action + **In [8]:** before = datetime.fromisoformat('2022-06-16T14:14:00.627446').timestamp() + **In [9]:** %timeit action.package_activity_list({}, {'id': 'api-package-1', 'before': before})3.17 ms ± 11.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) + **In [10]:** %timeit action.package_activity_list({}, {'id': 'api-package-1', 'offset': 9000})25.3 ms ± 504 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) + + ------------------------------- Troubleshooting ckan Commands