Skip to content

Commit

Permalink
Small changes to allow showoci to be imported by wrapper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stevario committed Apr 4, 2022
1 parent 9c3622d commit 6807f28
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 14 additions & 2 deletions examples/showoci/showoci.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
import sys
import argparse
import datetime
import contextlib
import os

version = "22.03.29"

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions examples/showoci/showoci_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
############################################
Expand Down
8 changes: 7 additions & 1 deletion examples/showoci/showoci_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6807f28

Please sign in to comment.