From 36bb7d203c6b3ec67013279f314b9664498c37b9 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 13 Oct 2023 08:37:44 +0200 Subject: [PATCH] Fix vm listing traceback and manpage strings Traceback (most recent call last): File "/usr/bin/resalloc-ibm-cloud-list-vms", line 8, in sys.exit(main()) ^^^^^^ File "/usr/lib/python3.12/site-packages/resalloc_ibm_cloud/ibm_cloud_list_vms.py", line 18, in main pool_id = opts.pool or os.getenv("RESALLOC_POOL_ID") ^^^^^^^^^ AttributeError: 'Namespace' object has no attribute 'pool' The manpages contained `argparsers.py` string, instead of the utility name, therefore defining prog= now. --- pyproject.toml | 4 ++-- resalloc_ibm_cloud/argparsers.py | 24 ++++++++++++++----- .../ibm_cloud_list_deleting_vms.py | 4 ++-- resalloc_ibm_cloud/ibm_cloud_list_vms.py | 4 ++-- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 620e2bf..0b2608c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,6 @@ build_manpages = "build_manpages.build_manpages" [tool.build_manpages] manpages = [ "man/resalloc-ibm-cloud-vm.1:function=vm_arg_parser:pyfile=resalloc_ibm_cloud/argparsers.py", - "man/resalloc-ibm-cloud-list-vms.1:function=vm_list_arg_parser:pyfile=resalloc_ibm_cloud/argparsers.py", - "man/resalloc-ibm-cloud-list-deleting-vms.1:function=default_arg_parser:pyfile=resalloc_ibm_cloud/argparsers.py", + "man/resalloc-ibm-cloud-list-vms.1:function=list_vms_parser:pyfile=resalloc_ibm_cloud/argparsers.py", + "man/resalloc-ibm-cloud-list-deleting-vms.1:function=list_deleting_vms_parser:pyfile=resalloc_ibm_cloud/argparsers.py", ] diff --git a/resalloc_ibm_cloud/argparsers.py b/resalloc_ibm_cloud/argparsers.py index 97062bd..5b2403f 100644 --- a/resalloc_ibm_cloud/argparsers.py +++ b/resalloc_ibm_cloud/argparsers.py @@ -5,12 +5,16 @@ import argparse -def default_arg_parser(): +def _pfx(name): + return "resalloc-ibm-cloud-" + name + + +def _default_arg_parser(prog=None): """ The part that every resalloc-ibm-cloud utility needs """ - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser(prog=prog) parser.add_argument( "--token-file", help="Path to IBM cloud token file", required=True ) @@ -26,7 +30,7 @@ def vm_arg_parser(): """ Parser for the resalloc-ibm-cloud-vm utility. """ - parser = default_arg_parser() + parser = _default_arg_parser(prog=_pfx("vm")) parser.add_argument("--log-level", default="info") subparsers = parser.add_subparsers(dest="subparser") @@ -66,10 +70,18 @@ def vm_arg_parser(): return parser -def vm_list_arg_parser(): +def _list_arg_parser(prog=None): """ - Parser for the resalloc-ibm-cloud-list-vms utility. + Parser for listing utilities """ - parser = default_arg_parser() + parser = _default_arg_parser(prog=prog) parser.add_argument("--pool") return parser + +def list_deleting_vms_parser(): + """ parser for listing vms """ + return _list_arg_parser(prog=_pfx("list-deleting-vms")) + +def list_vms_parser(): + """ parser for listing deleting vms """ + return _list_arg_parser(prog=_pfx("list-vms")) diff --git a/resalloc_ibm_cloud/ibm_cloud_list_deleting_vms.py b/resalloc_ibm_cloud/ibm_cloud_list_deleting_vms.py index 781eb02..f423962 100644 --- a/resalloc_ibm_cloud/ibm_cloud_list_deleting_vms.py +++ b/resalloc_ibm_cloud/ibm_cloud_list_deleting_vms.py @@ -3,14 +3,14 @@ """ from resalloc_ibm_cloud.helpers import get_service -from resalloc_ibm_cloud.argparsers import default_arg_parser +from resalloc_ibm_cloud.argparsers import list_deleting_vms_parser from resalloc_ibm_cloud.constants import LIMIT def main(): """Entrypoint to the script.""" - opts = default_arg_parser().parse_args() + opts = list_deleting_vms_parser().parse_args() cmd = f"source {opts.token_file} ; echo $IBMCLOUD_API_KEY" service = get_service(cmd, opts) diff --git a/resalloc_ibm_cloud/ibm_cloud_list_vms.py b/resalloc_ibm_cloud/ibm_cloud_list_vms.py index 2ee36cf..598634f 100755 --- a/resalloc_ibm_cloud/ibm_cloud_list_vms.py +++ b/resalloc_ibm_cloud/ibm_cloud_list_vms.py @@ -6,14 +6,14 @@ import sys from resalloc_ibm_cloud.helpers import get_service -from resalloc_ibm_cloud.argparsers import default_arg_parser +from resalloc_ibm_cloud.argparsers import list_vms_parser from resalloc_ibm_cloud.constants import LIMIT def main(): """An entrypoint to the script.""" - opts = default_arg_parser().parse_args() + opts = list_vms_parser().parse_args() pool_id = opts.pool or os.getenv("RESALLOC_POOL_ID") if not pool_id: