Skip to content

Commit a828b0d

Browse files
authored
Add -model_sample option to modelHelp (#624)
* JIRA WDT-320 Add -model_sample option to modelHelp * JIRA WDT-320 Corrections to unit tests and usage in start scripts
1 parent 6239acc commit a828b0d

File tree

9 files changed

+316
-44
lines changed

9 files changed

+316
-44
lines changed

core/src/main/python/model_help.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from wlsdeploy.exception import exception_helper
1616
from wlsdeploy.logging.platform_logger import PlatformLogger
1717
from wlsdeploy.tool.modelhelp.model_help_printer import ModelHelpPrinter
18+
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
1819
from wlsdeploy.tool.util import model_context_helper
1920
from wlsdeploy.util import cla_helper
2021
from wlsdeploy.util.cla_utils import CommandLineArgUtil
@@ -30,6 +31,7 @@
3031
__optional_arguments = [
3132
CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH,
3233
CommandLineArgUtil.FOLDERS_ONLY_SWITCH,
34+
CommandLineArgUtil.MODEL_SAMPLE_SWITCH,
3335
CommandLineArgUtil.RECURSIVE_SWITCH
3436
]
3537

@@ -84,19 +86,20 @@ def print_help(model_path, model_context):
8486
__logger.entering(model_path, class_name=_class_name, method_name=_method_name)
8587

8688
# default to NORMAL
87-
control_option = ModelHelpPrinter.ControlOptions.NORMAL
89+
control_option = ControlOptions.NORMAL
8890

8991
# determine control option using the model_context
9092
if model_context.get_recursive_control_option():
91-
control_option = ModelHelpPrinter.ControlOptions.RECURSIVE
93+
control_option = ControlOptions.RECURSIVE
9294
elif model_context.get_attributes_only_control_option():
93-
control_option = ModelHelpPrinter.ControlOptions.ATTRIBUTES_ONLY
95+
control_option = ControlOptions.ATTRIBUTES_ONLY
9496
elif model_context.get_folders_only_control_option():
95-
control_option = ModelHelpPrinter.ControlOptions.FOLDERS_ONLY
97+
control_option = ControlOptions.FOLDERS_ONLY
9698

9799
aliases = Aliases(model_context)
100+
as_sample = model_context.get_model_sample_option()
98101
printer = ModelHelpPrinter(aliases, __logger)
99-
printer.print_model_help(model_path, control_option)
102+
printer.print_model_help(model_path, control_option, as_sample)
100103

101104
__logger.exiting(class_name=_class_name, method_name=_method_name)
102105
return CommandLineArgUtil.PROG_OK_EXIT_CODE

core/src/main/python/wlsdeploy/tool/modelhelp/model_help_printer.py

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77
from oracle.weblogic.deploy.exception import ExceptionHelper
88
from wlsdeploy.aliases.location_context import LocationContext
99
from wlsdeploy.aliases.model_constants import KNOWN_TOPLEVEL_MODEL_SECTIONS
10+
from wlsdeploy.tool.modelhelp import model_help_utils
11+
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
12+
from wlsdeploy.tool.modelhelp.model_sample_printer import ModelSamplePrinter
1013
from wlsdeploy.util import model
11-
from wlsdeploy.util.enum import Enum
1214
from wlsdeploy.exception import exception_helper
1315
from wlsdeploy.exception.expection_types import ExceptionType
1416
from wlsdeploy.tool.util.alias_helper import AliasHelper
1517

16-
_class_name = "ModelHelper"
18+
_class_name = "ModelHelpPrinter"
1719
MODEL_PATH_PATTERN = re.compile(r'^([a-zA-Z]+:?)?((/[a-zA-Z0-9]+)*)?$')
1820

1921

2022
class ModelHelpPrinter(object):
2123
"""
2224
Class for printing the recognized model metadata to STDOUT.
2325
"""
24-
ControlOptions = Enum(['NORMAL', 'RECURSIVE', 'FOLDERS_ONLY', 'ATTRIBUTES_ONLY'])
2526

2627
def __init__(self, aliases, logger):
2728
"""
@@ -31,7 +32,7 @@ def __init__(self, aliases, logger):
3132
self._logger = logger
3233
self._alias_helper = AliasHelper(aliases, self._logger, ExceptionType.CLA)
3334

34-
def print_model_help(self, model_path, control_option):
35+
def print_model_help(self, model_path, control_option, as_sample=False):
3536
"""
3637
Prints out the help information for a given '''model_path'''. '''model_path''' needs to be specified
3738
using the following pattern:
@@ -46,17 +47,18 @@ def print_model_help(self, model_path, control_option):
4647
4748
:param model_path: a formatted string containing the model path
4849
:param control_option: a command-line switch that controls what is output
50+
:param as_sample: specifies that a model sample should be output
4951
:raises CLAException: if a problem is encountered
5052
"""
5153

5254
# print filter information, if not NORMAL
53-
if control_option == self.ControlOptions.RECURSIVE:
55+
if control_option == ControlOptions.RECURSIVE:
5456
print
5557
print _format_message('WLSDPLY-10102')
56-
elif control_option == self.ControlOptions.FOLDERS_ONLY:
58+
elif control_option == ControlOptions.FOLDERS_ONLY:
5759
print
5860
print _format_message('WLSDPLY-10103')
59-
elif control_option == self.ControlOptions.ATTRIBUTES_ONLY:
61+
elif control_option == ControlOptions.ATTRIBUTES_ONLY:
6062
print
6163
print _format_message('WLSDPLY-10104')
6264

@@ -65,12 +67,16 @@ def print_model_help(self, model_path, control_option):
6567
section_name = model_path_tokens[0]
6668
valid_section_folder_keys = self._alias_helper.get_model_section_top_level_folder_names(section_name)
6769

68-
if model_path_tokens[0] == 'top':
69-
self._print_model_top_level_help()
70-
elif len(model_path_tokens) == 1:
71-
self._print_model_section_help(section_name, valid_section_folder_keys, control_option)
70+
if as_sample:
71+
sample_printer = ModelSamplePrinter(self._alias_helper, self._logger)
72+
sample_printer.print_model_sample(model_path_tokens, control_option)
7273
else:
73-
self._print_model_folder_help(model_path_tokens, valid_section_folder_keys, control_option)
74+
if model_path_tokens[0] == 'top':
75+
self._print_model_top_level_help()
76+
elif len(model_path_tokens) == 1:
77+
self._print_model_section_help(section_name, valid_section_folder_keys, control_option)
78+
else:
79+
self._print_model_folder_help(model_path_tokens, valid_section_folder_keys, control_option)
7480

7581
def _parse_model_path(self, model_path):
7682
"""
@@ -182,20 +188,20 @@ def _print_model_section_help(self, section_name, valid_section_folder_keys, con
182188
print
183189
_print_indent(model_section, 0)
184190

185-
if self._show_attributes(control_option):
191+
if model_help_utils.show_attributes(control_option):
186192
attributes_location = self._alias_helper.get_model_section_attribute_location(section_name)
187193
if attributes_location is not None:
188194
self._print_attributes_help(attributes_location, 1)
189195

190-
if self._show_folders(control_option):
196+
if model_help_utils.show_folders(control_option):
191197
print
192198
_print_indent(_format_message('WLSDPLY-10107'), 1)
193199
valid_section_folder_keys.sort()
194200

195201
for section_folder_key in valid_section_folder_keys:
196202
_print_indent(section_folder_key, 2)
197203

198-
if control_option == self.ControlOptions.RECURSIVE:
204+
if control_option == ControlOptions.RECURSIVE:
199205
model_location = LocationContext().append_location(section_folder_key)
200206
self._print_subfolders_help(model_location, control_option, 2)
201207

@@ -210,7 +216,7 @@ def _print_model_folder_help(self, model_path_tokens, valid_section_folder_keys,
210216
_method_name = '_print_model_folder_help'
211217

212218
self._logger.finest('1 model_path_tokens={0}, control_option={1}, valid_section_folder_keys={0}',
213-
str(model_path_tokens), self.ControlOptions.from_value(control_option),
219+
str(model_path_tokens), ControlOptions.from_value(control_option),
214220
str(valid_section_folder_keys), class_name=_class_name, method_name=_method_name)
215221

216222
section_name = model_path_tokens[0]
@@ -242,11 +248,11 @@ def _print_model_folder_help(self, model_path_tokens, valid_section_folder_keys,
242248
print
243249
_print_indent(model_path, 0)
244250

245-
if self._show_attributes(control_option):
251+
if model_help_utils.show_attributes(control_option):
246252
# Print the attributes associated with location context
247253
self._print_attributes_help(model_location, 1)
248254

249-
if self._show_folders(control_option):
255+
if model_help_utils.show_folders(control_option):
250256
# Print the folders associated with location context
251257
print
252258
_print_indent(_format_message('WLSDPLY-10107'), 1)
@@ -289,7 +295,7 @@ def _print_subfolders_help(self, model_location, control_option, indent_level):
289295

290296
_print_indent(text, indent_level + 1)
291297

292-
if control_option == self.ControlOptions.RECURSIVE:
298+
if control_option == ControlOptions.RECURSIVE:
293299
# Call this method recursively
294300
self._print_subfolders_help(model_location, control_option, indent_level + 1)
295301

@@ -324,22 +330,6 @@ def _print_attributes_help(self, model_location, indent_level):
324330
msg = formatted_string % (attr_name, attr_infos[attr_name])
325331
_print_indent(msg, indent_level + 1)
326332

327-
def _show_attributes(self, control_option):
328-
"""
329-
Determine if attributes should be displayed, based on the control option.
330-
:param control_option: the control option to be checked
331-
:return: True if attributes should be displayed, False otherwise
332-
"""
333-
return control_option in [self.ControlOptions.NORMAL, self.ControlOptions.ATTRIBUTES_ONLY]
334-
335-
def _show_folders(self, control_option):
336-
"""
337-
Determine if folders should be displayed, based on the control option.
338-
:param control_option: the control option to be checked
339-
:return: True if folders should be displayed, False otherwise
340-
"""
341-
return control_option != self.ControlOptions.ATTRIBUTES_ONLY
342-
343333
def _get_folder_type_name(self, location):
344334
"""
345335
Return text indicating the type of a folder, such as "multiple".
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Copyright (c) 2020, Oracle Corporation and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
"""
5+
6+
from wlsdeploy.util.enum import Enum
7+
8+
ControlOptions = Enum(['NORMAL', 'RECURSIVE', 'FOLDERS_ONLY', 'ATTRIBUTES_ONLY'])
9+
10+
11+
def show_attributes(control_option):
12+
"""
13+
Determine if attributes should be displayed, based on the control option.
14+
:param control_option: the control option to be checked
15+
:return: True if attributes should be displayed, False otherwise
16+
"""
17+
return control_option in [ControlOptions.NORMAL, ControlOptions.ATTRIBUTES_ONLY]
18+
19+
20+
def show_folders(control_option):
21+
"""
22+
Determine if folders should be displayed, based on the control option.
23+
:param control_option: the control option to be checked
24+
:return: True if folders should be displayed, False otherwise
25+
"""
26+
return control_option != ControlOptions.ATTRIBUTES_ONLY

0 commit comments

Comments
 (0)