7
7
from oracle .weblogic .deploy .exception import ExceptionHelper
8
8
from wlsdeploy .aliases .location_context import LocationContext
9
9
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
10
13
from wlsdeploy .util import model
11
- from wlsdeploy .util .enum import Enum
12
14
from wlsdeploy .exception import exception_helper
13
15
from wlsdeploy .exception .expection_types import ExceptionType
14
16
from wlsdeploy .tool .util .alias_helper import AliasHelper
15
17
16
- _class_name = "ModelHelper "
18
+ _class_name = "ModelHelpPrinter "
17
19
MODEL_PATH_PATTERN = re .compile (r'^([a-zA-Z]+:?)?((/[a-zA-Z0-9]+)*)?$' )
18
20
19
21
20
22
class ModelHelpPrinter (object ):
21
23
"""
22
24
Class for printing the recognized model metadata to STDOUT.
23
25
"""
24
- ControlOptions = Enum (['NORMAL' , 'RECURSIVE' , 'FOLDERS_ONLY' , 'ATTRIBUTES_ONLY' ])
25
26
26
27
def __init__ (self , aliases , logger ):
27
28
"""
@@ -31,7 +32,7 @@ def __init__(self, aliases, logger):
31
32
self ._logger = logger
32
33
self ._alias_helper = AliasHelper (aliases , self ._logger , ExceptionType .CLA )
33
34
34
- def print_model_help (self , model_path , control_option ):
35
+ def print_model_help (self , model_path , control_option , as_sample = False ):
35
36
"""
36
37
Prints out the help information for a given '''model_path'''. '''model_path''' needs to be specified
37
38
using the following pattern:
@@ -46,17 +47,18 @@ def print_model_help(self, model_path, control_option):
46
47
47
48
:param model_path: a formatted string containing the model path
48
49
:param control_option: a command-line switch that controls what is output
50
+ :param as_sample: specifies that a model sample should be output
49
51
:raises CLAException: if a problem is encountered
50
52
"""
51
53
52
54
# print filter information, if not NORMAL
53
- if control_option == self . ControlOptions .RECURSIVE :
55
+ if control_option == ControlOptions .RECURSIVE :
54
56
print
55
57
print _format_message ('WLSDPLY-10102' )
56
- elif control_option == self . ControlOptions .FOLDERS_ONLY :
58
+ elif control_option == ControlOptions .FOLDERS_ONLY :
57
59
print
58
60
print _format_message ('WLSDPLY-10103' )
59
- elif control_option == self . ControlOptions .ATTRIBUTES_ONLY :
61
+ elif control_option == ControlOptions .ATTRIBUTES_ONLY :
60
62
print
61
63
print _format_message ('WLSDPLY-10104' )
62
64
@@ -65,12 +67,16 @@ def print_model_help(self, model_path, control_option):
65
67
section_name = model_path_tokens [0 ]
66
68
valid_section_folder_keys = self ._alias_helper .get_model_section_top_level_folder_names (section_name )
67
69
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 )
72
73
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 )
74
80
75
81
def _parse_model_path (self , model_path ):
76
82
"""
@@ -182,20 +188,20 @@ def _print_model_section_help(self, section_name, valid_section_folder_keys, con
182
188
print
183
189
_print_indent (model_section , 0 )
184
190
185
- if self . _show_attributes (control_option ):
191
+ if model_help_utils . show_attributes (control_option ):
186
192
attributes_location = self ._alias_helper .get_model_section_attribute_location (section_name )
187
193
if attributes_location is not None :
188
194
self ._print_attributes_help (attributes_location , 1 )
189
195
190
- if self . _show_folders (control_option ):
196
+ if model_help_utils . show_folders (control_option ):
191
197
print
192
198
_print_indent (_format_message ('WLSDPLY-10107' ), 1 )
193
199
valid_section_folder_keys .sort ()
194
200
195
201
for section_folder_key in valid_section_folder_keys :
196
202
_print_indent (section_folder_key , 2 )
197
203
198
- if control_option == self . ControlOptions .RECURSIVE :
204
+ if control_option == ControlOptions .RECURSIVE :
199
205
model_location = LocationContext ().append_location (section_folder_key )
200
206
self ._print_subfolders_help (model_location , control_option , 2 )
201
207
@@ -210,7 +216,7 @@ def _print_model_folder_help(self, model_path_tokens, valid_section_folder_keys,
210
216
_method_name = '_print_model_folder_help'
211
217
212
218
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 ),
214
220
str (valid_section_folder_keys ), class_name = _class_name , method_name = _method_name )
215
221
216
222
section_name = model_path_tokens [0 ]
@@ -242,11 +248,11 @@ def _print_model_folder_help(self, model_path_tokens, valid_section_folder_keys,
242
248
print
243
249
_print_indent (model_path , 0 )
244
250
245
- if self . _show_attributes (control_option ):
251
+ if model_help_utils . show_attributes (control_option ):
246
252
# Print the attributes associated with location context
247
253
self ._print_attributes_help (model_location , 1 )
248
254
249
- if self . _show_folders (control_option ):
255
+ if model_help_utils . show_folders (control_option ):
250
256
# Print the folders associated with location context
251
257
print
252
258
_print_indent (_format_message ('WLSDPLY-10107' ), 1 )
@@ -289,7 +295,7 @@ def _print_subfolders_help(self, model_location, control_option, indent_level):
289
295
290
296
_print_indent (text , indent_level + 1 )
291
297
292
- if control_option == self . ControlOptions .RECURSIVE :
298
+ if control_option == ControlOptions .RECURSIVE :
293
299
# Call this method recursively
294
300
self ._print_subfolders_help (model_location , control_option , indent_level + 1 )
295
301
@@ -324,22 +330,6 @@ def _print_attributes_help(self, model_location, indent_level):
324
330
msg = formatted_string % (attr_name , attr_infos [attr_name ])
325
331
_print_indent (msg , indent_level + 1 )
326
332
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
-
343
333
def _get_folder_type_name (self , location ):
344
334
"""
345
335
Return text indicating the type of a folder, such as "multiple".
0 commit comments