Skip to content

Commit 6807f28

Browse files
committed
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.
1 parent 9c3622d commit 6807f28

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

examples/showoci/showoci.py

Lines changed: 14 additions & 2 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,17 @@ 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:
346+
return False
347+
336348

337349
if len(sys.argv) < 2:
338350
parser.print_help()

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+
# Initate 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+
# Initate summary objects everytime 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)