77from oracle .weblogic .deploy .exception import ExceptionHelper
88from wlsdeploy .aliases .location_context import LocationContext
99from 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
1013from wlsdeploy .util import model
11- from wlsdeploy .util .enum import Enum
1214from wlsdeploy .exception import exception_helper
1315from wlsdeploy .exception .expection_types import ExceptionType
1416from wlsdeploy .tool .util .alias_helper import AliasHelper
1517
16- _class_name = "ModelHelper "
18+ _class_name = "ModelHelpPrinter "
1719MODEL_PATH_PATTERN = re .compile (r'^([a-zA-Z]+:?)?((/[a-zA-Z0-9]+)*)?$' )
1820
1921
2022class 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".
0 commit comments