From 9c3622d40ef13aff098662e48d8f49ab52332042 Mon Sep 17 00:00:00 2001 From: Stephen R Persky Date: Mon, 4 Apr 2022 16:27:29 -0400 Subject: [PATCH 1/4] Update showoci.py --- examples/showoci/showoci.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/showoci/showoci.py b/examples/showoci/showoci.py index 80694334c9..01aee9b0aa 100755 --- a/examples/showoci/showoci.py +++ b/examples/showoci/showoci.py @@ -489,4 +489,5 @@ def print_to_json_file(output, file_name, data, header): ########################################################################## # Main ########################################################################## -execute_extract() +if __name__ == "__main__": + execute_extract() From 6807f283aaa258617cf16a6198c897561460f26d Mon Sep 17 00:00:00 2001 From: Stephen R Persky Date: Mon, 4 Apr 2022 16:41:36 -0400 Subject: [PATCH 2/4] Small changes to allow showoci to be imported by wrapper Add initialization of data structures to __init__ routines of classes. Add the ability to call the argument parser with a command line built in a calling routine. This allows a wrapper to build command lines. --- examples/showoci/showoci.py | 16 ++++++++++++++-- examples/showoci/showoci_data.py | 3 +++ examples/showoci/showoci_output.py | 8 +++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/examples/showoci/showoci.py b/examples/showoci/showoci.py index 01aee9b0aa..6d8d19d99d 100755 --- a/examples/showoci/showoci.py +++ b/examples/showoci/showoci.py @@ -104,6 +104,8 @@ import sys import argparse import datetime +import contextlib +import os version = "22.03.29" @@ -280,7 +282,7 @@ def return_error_message(service_error, service_warning, data_error, output_erro ########################################################################## # set parser ########################################################################## -def set_parser_arguments(): +def set_parser_arguments(argsList=[]): parser = argparse.ArgumentParser(formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=80, width=130)) parser.add_argument('-a', action='store_true', default=False, dest='all', help='Print All Resources') parser.add_argument('-ani', action='store_true', default=False, dest='allnoiam', help='Print All Resources but identity') @@ -332,7 +334,17 @@ def set_parser_arguments(): parser.add_argument('-caches', action='store_true', default=False, dest='servicescr', help="Output Cache to screen (JSON format)") parser.add_argument('--version', action='version', version='%(prog)s ' + version) - result = parser.parse_args() + + if not argsList: + result = parser.parse_args() + else: + with contextlib.redirect_stdout(os.devnull): + try: + result = parser.parse_args(args=argsList) + return result + except: + return False + if len(sys.argv) < 2: parser.print_help() diff --git a/examples/showoci/showoci_data.py b/examples/showoci/showoci_data.py index c8eb87e5f7..2b603d17cf 100755 --- a/examples/showoci/showoci_data.py +++ b/examples/showoci/showoci_data.py @@ -41,6 +41,9 @@ def __init__(self, flags): # initiate service object self.service = ShowOCIService(flags) + # Initate data list everytime class is instantiated + self.data = [] + ############################################ # get service data ############################################ diff --git a/examples/showoci/showoci_output.py b/examples/showoci/showoci_output.py index bf5b3e5da9..161ad1d498 100755 --- a/examples/showoci/showoci_output.py +++ b/examples/showoci/showoci_output.py @@ -2647,7 +2647,13 @@ class ShowOCISummary(object): # Init ############################################ def __init__(self): - pass + + # Initate summary objects everytime class is instantiated + self.summary_global_list = [] + self.summary_global_data = [] + self.summary_global_region_total = [] + self.summary_global_region_json = {} + self.summary_global_total = [] ########################################################################## # get summary total From 94050e4b6b8986c6d1aa2b99a86f7b4af5136787 Mon Sep 17 00:00:00 2001 From: Stephen R Persky Date: Tue, 5 Apr 2022 08:37:51 -0400 Subject: [PATCH 3/4] Updates per request Two updates per request from owner. Changed return False to return None in the showoci.set_parter_arguments routine Fixed typos/spelling errors in Initiate comments --- examples/showoci/showoci.py | 2 +- examples/showoci/showoci_data.py | 2 +- examples/showoci/showoci_output.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/showoci/showoci.py b/examples/showoci/showoci.py index 6d8d19d99d..f139dddbc5 100755 --- a/examples/showoci/showoci.py +++ b/examples/showoci/showoci.py @@ -343,7 +343,7 @@ def set_parser_arguments(argsList=[]): result = parser.parse_args(args=argsList) return result except: - return False + return None if len(sys.argv) < 2: diff --git a/examples/showoci/showoci_data.py b/examples/showoci/showoci_data.py index 2b603d17cf..a62a2676e7 100755 --- a/examples/showoci/showoci_data.py +++ b/examples/showoci/showoci_data.py @@ -41,7 +41,7 @@ def __init__(self, flags): # initiate service object self.service = ShowOCIService(flags) - # Initate data list everytime class is instantiated + # Initiate data list everytime class is instantiated self.data = [] ############################################ diff --git a/examples/showoci/showoci_output.py b/examples/showoci/showoci_output.py index 161ad1d498..a99bd714d3 100755 --- a/examples/showoci/showoci_output.py +++ b/examples/showoci/showoci_output.py @@ -2648,7 +2648,7 @@ class ShowOCISummary(object): ############################################ def __init__(self): - # Initate summary objects everytime class is instantiated + # Initiate summary objects every time class is instantiated self.summary_global_list = [] self.summary_global_data = [] self.summary_global_region_total = [] From cd18723a574334524bc600123ccd7479a78a3a43 Mon Sep 17 00:00:00 2001 From: Stephen R Persky Date: Tue, 5 Apr 2022 10:45:16 -0400 Subject: [PATCH 4/4] Update showoci.py --- examples/showoci/showoci.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/showoci/showoci.py b/examples/showoci/showoci.py index f139dddbc5..b7ef93f49b 100755 --- a/examples/showoci/showoci.py +++ b/examples/showoci/showoci.py @@ -342,10 +342,9 @@ def set_parser_arguments(argsList=[]): try: result = parser.parse_args(args=argsList) return result - except: + except Exception: return None - if len(sys.argv) < 2: parser.print_help() return None @@ -503,3 +502,4 @@ def print_to_json_file(output, file_name, data, header): ########################################################################## if __name__ == "__main__": execute_extract() +