Skip to content

Commit 855adcf

Browse files
authored
Merge pull request #446 from stevario/master
Small changes to allow showoci to be imported by wrapper
2 parents 9887377 + cd18723 commit 855adcf

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

examples/showoci/showoci.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
import sys
105105
import argparse
106106
import datetime
107+
import contextlib
108+
import os
107109

108110
version = "22.03.29"
109111

@@ -280,7 +282,7 @@ def return_error_message(service_error, service_warning, data_error, output_erro
280282
##########################################################################
281283
# set parser
282284
##########################################################################
283-
def set_parser_arguments():
285+
def set_parser_arguments(argsList=[]):
284286
parser = argparse.ArgumentParser(formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=80, width=130))
285287
parser.add_argument('-a', action='store_true', default=False, dest='all', help='Print All Resources')
286288
parser.add_argument('-ani', action='store_true', default=False, dest='allnoiam', help='Print All Resources but identity')
@@ -332,7 +334,16 @@ def set_parser_arguments():
332334
parser.add_argument('-caches', action='store_true', default=False, dest='servicescr', help="Output Cache to screen (JSON format)")
333335
parser.add_argument('--version', action='version', version='%(prog)s ' + version)
334336

335-
result = parser.parse_args()
337+
338+
if not argsList:
339+
result = parser.parse_args()
340+
else:
341+
with contextlib.redirect_stdout(os.devnull):
342+
try:
343+
result = parser.parse_args(args=argsList)
344+
return result
345+
except Exception:
346+
return None
336347

337348
if len(sys.argv) < 2:
338349
parser.print_help()
@@ -489,4 +500,6 @@ def print_to_json_file(output, file_name, data, header):
489500
##########################################################################
490501
# Main
491502
##########################################################################
492-
execute_extract()
503+
if __name__ == "__main__":
504+
execute_extract()
505+

examples/showoci/showoci_data.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def __init__(self, flags):
4141
# initiate service object
4242
self.service = ShowOCIService(flags)
4343

44+
# Initiate data list everytime class is instantiated
45+
self.data = []
46+
4447
############################################
4548
# get service data
4649
############################################

examples/showoci/showoci_output.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,13 @@ class ShowOCISummary(object):
26472647
# Init
26482648
############################################
26492649
def __init__(self):
2650-
pass
2650+
2651+
# Initiate summary objects every time class is instantiated
2652+
self.summary_global_list = []
2653+
self.summary_global_data = []
2654+
self.summary_global_region_total = []
2655+
self.summary_global_region_json = {}
2656+
self.summary_global_total = []
26512657

26522658
##########################################################################
26532659
# get summary total

0 commit comments

Comments
 (0)