Skip to content

Commit 528f000

Browse files
authored
Model help enhancements (#674)
* JIRA WDT-435 - Use model sample format always; align data type comments; clarify format details * JIRA WDT-435 - Show artificial type folders correctly in output
1 parent 686890c commit 528f000

File tree

8 files changed

+71
-289
lines changed

8 files changed

+71
-289
lines changed

core/src/main/python/model_help.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
__optional_arguments = [
3232
CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH,
3333
CommandLineArgUtil.FOLDERS_ONLY_SWITCH,
34-
CommandLineArgUtil.MODEL_SAMPLE_SWITCH,
35-
CommandLineArgUtil.RECURSIVE_SWITCH
34+
CommandLineArgUtil.RECURSIVE_SWITCH,
35+
# deprecated
36+
CommandLineArgUtil.MODEL_SAMPLE_SWITCH
3637
]
3738

3839
__output_types = [
@@ -65,6 +66,10 @@ def __process_args(args):
6566
raise ex
6667
found = True
6768

69+
if CommandLineArgUtil.MODEL_SAMPLE_SWITCH in argument_map:
70+
__logger.warning('WLSDPLY-10106', CommandLineArgUtil.MODEL_SAMPLE_SWITCH,
71+
class_name=_class_name, method_name=_method_name)
72+
6873
return model_context_helper.create_context(_program_name, argument_map)
6974

7075

@@ -92,9 +97,8 @@ def print_help(model_path, model_context):
9297
control_option = ControlOptions.FOLDERS_ONLY
9398

9499
aliases = Aliases(model_context)
95-
as_sample = model_context.get_model_sample_option()
96100
printer = ModelHelpPrinter(aliases, __logger)
97-
printer.print_model_help(model_path, control_option, as_sample)
101+
printer.print_model_help(model_path, control_option)
98102

99103
__logger.exiting(class_name=_class_name, method_name=_method_name)
100104
return CommandLineArgUtil.PROG_OK_EXIT_CODE

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

Lines changed: 18 additions & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
import re
66

77
from oracle.weblogic.deploy.exception import ExceptionHelper
8-
from wlsdeploy.aliases.location_context import LocationContext
8+
99
from wlsdeploy.aliases.model_constants import KNOWN_TOPLEVEL_MODEL_SECTIONS
10-
from wlsdeploy.aliases.validation_codes import ValidationCodes
11-
from wlsdeploy.tool.modelhelp import model_help_utils
12-
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
13-
from wlsdeploy.tool.modelhelp.model_sample_printer import ModelSamplePrinter
14-
from wlsdeploy.util import model
1510
from wlsdeploy.exception import exception_helper
1611
from wlsdeploy.exception.expection_types import ExceptionType
12+
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
13+
from wlsdeploy.tool.modelhelp.model_sample_printer import ModelSamplePrinter
1714
from wlsdeploy.tool.util.alias_helper import AliasHelper
15+
from wlsdeploy.util import model
1816

1917
_class_name = "ModelHelpPrinter"
2018
MODEL_PATH_PATTERN = re.compile(r'^([a-zA-Z]+:?)?((/[a-zA-Z0-9]+)*)?$')
@@ -33,7 +31,7 @@ def __init__(self, aliases, logger):
3331
self._logger = logger
3432
self._alias_helper = AliasHelper(aliases, self._logger, ExceptionType.CLA)
3533

36-
def print_model_help(self, model_path, control_option, as_sample=False):
34+
def print_model_help(self, model_path, control_option):
3735
"""
3836
Prints out the help information for a given '''model_path'''. '''model_path''' needs to be specified
3937
using the following pattern:
@@ -48,36 +46,26 @@ def print_model_help(self, model_path, control_option, as_sample=False):
4846
4947
:param model_path: a formatted string containing the model path
5048
:param control_option: a command-line switch that controls what is output
51-
:param as_sample: specifies that a model sample should be output
5249
:raises CLAException: if a problem is encountered
5350
"""
5451

55-
# print filter information, if not NORMAL
52+
model_path_tokens = self._parse_model_path(model_path)
53+
folder_path = '/'.join(model_path_tokens[1:])
54+
model_path = '%s:/%s' % (model_path_tokens[0], folder_path)
55+
56+
# print format information
57+
print
5658
if control_option == ControlOptions.RECURSIVE:
57-
print
58-
print _format_message('WLSDPLY-10102')
59+
print _format_message('WLSDPLY-10102', model_path)
5960
elif control_option == ControlOptions.FOLDERS_ONLY:
60-
print
61-
print _format_message('WLSDPLY-10103')
61+
print _format_message('WLSDPLY-10103', model_path)
6262
elif control_option == ControlOptions.ATTRIBUTES_ONLY:
63-
print
64-
print _format_message('WLSDPLY-10104')
65-
66-
model_path_tokens = self._parse_model_path(model_path)
67-
68-
section_name = model_path_tokens[0]
69-
valid_section_folder_keys = self._alias_helper.get_model_section_top_level_folder_names(section_name)
70-
71-
if as_sample:
72-
sample_printer = ModelSamplePrinter(self._alias_helper, self._logger)
73-
sample_printer.print_model_sample(model_path_tokens, control_option)
63+
print _format_message('WLSDPLY-10104', model_path)
7464
else:
75-
if model_path_tokens[0] == 'top':
76-
self._print_model_top_level_help()
77-
elif len(model_path_tokens) == 1:
78-
self._print_model_section_help(section_name, valid_section_folder_keys, control_option)
79-
else:
80-
self._print_model_folder_help(model_path_tokens, valid_section_folder_keys, control_option)
65+
print _format_message('WLSDPLY-10105', model_path)
66+
67+
sample_printer = ModelSamplePrinter(self._alias_helper, self._logger)
68+
sample_printer.print_model_sample(model_path_tokens, control_option)
8169

8270
def _parse_model_path(self, model_path):
8371
"""
@@ -150,206 +138,6 @@ def _get_section_for_folder_list(self, folder_list):
150138
self._logger.throwing(ex, class_name=_class_name, method_name=_method_name)
151139
raise ex
152140

153-
def _print_model_top_level_help(self):
154-
"""
155-
Prints out all the valid section names for a model.
156-
The -recursive flag is disregarded for this case.
157-
"""
158-
_method_name = '_print_model_top_level_help'
159-
self._logger.finest('sections={0}', KNOWN_TOPLEVEL_MODEL_SECTIONS, class_name=_class_name,
160-
method_name=_method_name)
161-
162-
title = _format_message('WLSDPLY-10113')
163-
164-
# Print 'All Sections:' header
165-
print
166-
_print_indent(title, 0)
167-
print
168-
169-
for section in KNOWN_TOPLEVEL_MODEL_SECTIONS:
170-
_print_indent(section, 1)
171-
172-
def _print_model_section_help(self, section_name, valid_section_folder_keys, control_option):
173-
"""
174-
Prints the help for a section of a model, when just the section_name[:] is provided
175-
:param section_name: the name of the model section
176-
:param valid_section_folder_keys: list of the valid top folders in the specified section
177-
:param control_option: A command-line switch that controls what is output to STDOUT
178-
"""
179-
_method_name = '_print_model_section_help'
180-
181-
self._logger.finest('1 section_name={0}', section_name, class_name=_class_name, method_name=_method_name)
182-
183-
location_path = '%s:' % section_name
184-
self._logger.finest('1 location_path={0}', location_path, class_name=_class_name, method_name=_method_name)
185-
186-
model_section = _format_message('WLSDPLY-10106', location_path)
187-
188-
# Print 'Section: <model_section>' label and field
189-
print
190-
_print_indent(model_section, 0)
191-
192-
if model_help_utils.show_attributes(control_option):
193-
attributes_location = self._alias_helper.get_model_section_attribute_location(section_name)
194-
if attributes_location is not None:
195-
self._print_attributes_help(attributes_location, 1)
196-
197-
if model_help_utils.show_folders(control_option):
198-
print
199-
_print_indent(_format_message('WLSDPLY-10107'), 1)
200-
valid_section_folder_keys.sort()
201-
202-
for section_folder_key in valid_section_folder_keys:
203-
_print_indent(section_folder_key, 2)
204-
205-
if control_option == ControlOptions.RECURSIVE:
206-
model_location = LocationContext().append_location(section_folder_key)
207-
self._print_subfolders_help(model_location, control_option, 2)
208-
209-
def _print_model_folder_help(self, model_path_tokens, valid_section_folder_keys, control_option):
210-
"""
211-
Prints the help for a folder in a model, when more than just the section_name[:] is provided.
212-
The section name in the first token was already validated.
213-
:param model_path_tokens: a Python list of path elements built from model path
214-
:param valid_section_folder_keys: A list of valid folder names for the model section in the path
215-
:param control_option: A command-line switch that controls what is output to STDOUT
216-
"""
217-
_method_name = '_print_model_folder_help'
218-
219-
self._logger.finest('1 model_path_tokens={0}, control_option={1}, valid_section_folder_keys={0}',
220-
str(model_path_tokens), ControlOptions.from_value(control_option),
221-
str(valid_section_folder_keys), class_name=_class_name, method_name=_method_name)
222-
223-
print
224-
225-
section_name = model_path_tokens[0]
226-
top_folder = model_path_tokens[1]
227-
if top_folder not in valid_section_folder_keys:
228-
ex = exception_helper.create_cla_exception('WLSDPLY-10110', section_name + ':', top_folder,
229-
', '.join(valid_section_folder_keys))
230-
self._logger.throwing(ex, class_name=_class_name, method_name=_method_name)
231-
raise ex
232-
233-
# Populate the location context using model_path_tokens[1:]
234-
model_location = LocationContext()
235-
for folder_key in model_path_tokens[1:]:
236-
code, message = self._alias_helper.is_valid_model_folder_name(model_location, folder_key)
237-
if code != ValidationCodes.VALID:
238-
ex = exception_helper.create_cla_exception("WLSDPLY-05027", message)
239-
self._logger.throwing(ex, class_name=_class_name, method_name=_method_name)
240-
raise ex
241-
242-
model_location.append_location(folder_key)
243-
name_token = self._alias_helper.get_name_token(model_location)
244-
if name_token is not None:
245-
model_location.add_name_token(name_token, '%s-0' % folder_key)
246-
247-
self._logger.finest('2 model_location={0}', model_location, class_name=_class_name,
248-
method_name=_method_name)
249-
250-
folder_path = '/'.join(model_path_tokens[1:])
251-
model_path = _format_message('WLSDPLY-10105', '%s:/%s' % (section_name, folder_path))
252-
type_name = self._get_folder_type_name(model_location)
253-
if type_name is not None:
254-
model_path += " (" + type_name + ")"
255-
256-
# Print 'Path: <model_section>' header
257-
_print_indent(model_path, 0)
258-
259-
if model_help_utils.show_attributes(control_option):
260-
# Print the attributes associated with location context
261-
self._print_attributes_help(model_location, 1)
262-
263-
if model_help_utils.show_folders(control_option):
264-
# Print the folders associated with location context
265-
print
266-
_print_indent(_format_message('WLSDPLY-10107'), 1)
267-
self._print_subfolders_help(model_location, control_option, 1)
268-
269-
self._logger.exiting(class_name=_class_name, method_name=_method_name)
270-
return
271-
272-
def _print_subfolders_help(self, model_location, control_option, indent_level):
273-
"""
274-
Prints the help for the folders in a model location, without header or leading space.
275-
:param model_location: the model location being worked on
276-
:param control_option: a command-line switch that controls what is output to STDOUT
277-
:param indent_level: the level to indent by, before printing output
278-
"""
279-
_method_name = '_print_subfolders_help'
280-
281-
valid_subfolder_keys = self._alias_helper.get_model_subfolder_names(model_location)
282-
self._logger.finest('3 aliases.get_model_subfolder_names(model_location) returned: {0}',
283-
str(valid_subfolder_keys), class_name=_class_name, method_name=_method_name)
284-
285-
if not valid_subfolder_keys:
286-
return
287-
288-
valid_subfolder_keys.sort()
289-
290-
for key in valid_subfolder_keys:
291-
model_location.append_location(key)
292-
name_token = self._alias_helper.get_name_token(model_location)
293-
if name_token is not None:
294-
model_location.add_name_token(name_token, '%s-0' % key)
295-
296-
self._logger.finest('3 model_location={0}', model_location, class_name=_class_name,
297-
method_name=_method_name)
298-
299-
text = key
300-
type_name = self._get_folder_type_name(model_location)
301-
if type_name is not None:
302-
text += " (" + type_name + ")"
303-
304-
_print_indent(text, indent_level + 1)
305-
306-
if control_option == ControlOptions.RECURSIVE:
307-
# Call this method recursively
308-
self._print_subfolders_help(model_location, control_option, indent_level + 1)
309-
310-
model_location.pop_location()
311-
312-
def _print_attributes_help(self, model_location, indent_level):
313-
"""
314-
Prints out the help for the attributes in a model location
315-
:param model_location: An object containing data about the model location being worked on
316-
:param indent_level: The level to indent by, before printing output
317-
"""
318-
_method_name = '_print_attributes_help'
319-
320-
attr_infos = self._alias_helper.get_model_attribute_names_and_types(model_location)
321-
self._logger.finer('WLSDPLY-05012', str(model_location), str(attr_infos),
322-
class_name=_class_name, method_name=_method_name)
323-
324-
# Print 'Valid Attributes:' area label
325-
print
326-
_print_indent(_format_message('WLSDPLY-10111'), indent_level)
327-
328-
if attr_infos:
329-
maxlen = 0
330-
for key in attr_infos:
331-
if len(key) > maxlen:
332-
maxlen = len(key)
333-
formatted_string = '%-' + str(maxlen) + 's\t%s'
334-
335-
attr_list = attr_infos.keys()
336-
attr_list.sort()
337-
for attr_name in attr_list:
338-
msg = formatted_string % (attr_name, attr_infos[attr_name])
339-
_print_indent(msg, indent_level + 1)
340-
341-
def _get_folder_type_name(self, location):
342-
"""
343-
Return text indicating the type of a folder, such as "multiple".
344-
:param location: the location to be checked
345-
:return: name of the folder type to be displayed, or None
346-
"""
347-
if self._alias_helper.is_artificial_type_folder(location):
348-
return None
349-
if self._alias_helper.supports_multiple_mbean_instances(location):
350-
return "multiple"
351-
return None
352-
353141

354142
def _format_message(key, *args):
355143
"""
@@ -358,17 +146,3 @@ def _format_message(key, *args):
358146
:return: the formatted text message
359147
"""
360148
return ExceptionHelper.getMessage(key, list(args))
361-
362-
363-
def _print_indent(msg, level=1):
364-
"""
365-
Print a message at the specified indent level.
366-
:param msg: the message to be printed
367-
:param level: the indent level
368-
"""
369-
result = ''
370-
i = 0
371-
while i < level:
372-
result += ' '
373-
i += 1
374-
print '%s%s' % (result, msg)

0 commit comments

Comments
 (0)