@@ -46,10 +46,10 @@ def _print_model_section_sample(self, section_name, control_option):
46
46
_print_indent (path , 0 )
47
47
48
48
if model_help_utils .show_attributes (control_option ):
49
- self ._print_attributes_sample (self ._schema , 1 )
49
+ self ._print_attributes_sample (self ._schema , 1 , False )
50
50
51
51
if model_help_utils .show_folders (control_option ):
52
- self ._print_subfolders_sample (self ._schema , control_option , 1 , path )
52
+ self ._print_subfolders_sample (self ._schema , control_option , 1 , path , False )
53
53
54
54
def _print_model_folder_sample (self , section_name , model_path_tokens , control_option ):
55
55
"""
@@ -69,6 +69,7 @@ def _print_model_folder_sample(self, section_name, model_path_tokens, control_op
69
69
_print_indent (section_name + ":" , indent )
70
70
indent += 1
71
71
72
+ in_object_array = False
72
73
model_path = section_name + ":"
73
74
current_folder = self ._schema
74
75
for token in model_path_tokens [1 :]:
@@ -83,31 +84,30 @@ def _print_model_folder_sample(self, section_name, model_path_tokens, control_op
83
84
84
85
current_folder = properties [token ]
85
86
86
- _print_indent (token + ":" , indent )
87
+ _print_indent (token + ":" , indent , in_object_array )
87
88
indent += 1
88
89
89
- if wko_schema_helper .is_object_array (current_folder ):
90
- name = token + '-1'
91
- _print_indent (name + ":" , indent )
92
- indent += 1
93
-
90
+ # apply to the next folder in the path
91
+ in_object_array = wko_schema_helper .is_object_array (current_folder )
94
92
model_path = model_path + "/" + token
95
93
96
94
# list the attributes and folders, as specified
97
95
98
96
if model_help_utils .show_attributes (control_option ):
99
97
# Print the attributes associated with schema folder
100
- self ._print_attributes_sample (current_folder , indent )
98
+ in_object_array = self ._print_attributes_sample (current_folder , indent , in_object_array )
101
99
102
100
if model_help_utils .show_folders (control_option ):
103
- self ._print_subfolders_sample (current_folder , control_option , indent , model_path )
101
+ self ._print_subfolders_sample (current_folder , control_option , indent , model_path , in_object_array )
104
102
105
- def _print_subfolders_sample (self , schema_folder , control_option , indent_level , path ):
103
+ def _print_subfolders_sample (self , schema_folder , control_option , indent_level , path , in_object_array ):
106
104
"""
107
105
Prints a model sample section for the folders in a model location.
108
106
:param schema_folder: the schema folder being printed
109
107
:param control_option: a command-line switch that controls what is output to STDOUT
110
108
:param indent_level: the level to indent by, before printing output
109
+ :param path: indicates path to request for child folder help
110
+ :param in_object_array: if True, a hyphen is printed before the first attribute
111
111
"""
112
112
_method_name = '_print_subfolders_sample'
113
113
@@ -135,27 +135,29 @@ def _print_subfolders_sample(self, schema_folder, control_option, indent_level,
135
135
if control_option != ControlOptions .RECURSIVE :
136
136
print ("" )
137
137
138
- key_level = indent_level
139
- _print_indent ( key + ":" , key_level )
138
+ _print_indent ( key + ":" , indent_level , in_object_array )
139
+ in_object_array = False
140
140
141
- child_level = key_level
142
- if key in multi_folders :
143
- name = key + "-1"
144
- child_level += 1
145
- _print_indent (name + ":" , child_level )
141
+ child_level = indent_level + 1
146
142
143
+ next_path = path + "/" + key
147
144
if control_option == ControlOptions .RECURSIVE :
148
145
# Call this method recursively
149
- self ._print_subfolders_sample (folder_info , control_option , child_level + 1 , path )
146
+ child_in_object_array = key in multi_folders
147
+ self ._print_subfolders_sample (folder_info , control_option , child_level , path ,
148
+ child_in_object_array )
150
149
else :
151
- next_path = path + "/" + key
152
- _print_indent ("# see " + next_path , child_level + 1 )
150
+ _print_indent ("# see " + next_path , child_level )
151
+
152
+ return in_object_array
153
153
154
- def _print_attributes_sample (self , schema_folder , indent_level ):
154
+ def _print_attributes_sample (self , schema_folder , indent_level , in_object_array ):
155
155
"""
156
156
Prints a model sample for the attributes in a model location
157
157
:param schema_folder: the schema folder to be printed
158
158
:param indent_level: the level of indentation for this folder
159
+ :param in_object_array: if True, a hyphen is printed before the first attribute
160
+ :return: value of in_object_array, or False if an attribute was printed with a hyphen
159
161
"""
160
162
_method_name = '_print_attributes_sample'
161
163
@@ -192,10 +194,13 @@ def _print_attributes_sample(self, schema_folder, indent_level):
192
194
format_string = '%-' + str (maxlen + 1 ) + 's # %s'
193
195
for attr_name in attr_list :
194
196
line = format_string % (attr_name + ":" , attribute_map [attr_name ])
195
- _print_indent (line , indent_level )
197
+ _print_indent (line , indent_level , in_object_array )
198
+ in_object_array = False
196
199
else :
197
200
_print_indent ("# no attributes" , indent_level )
198
201
202
+ return in_object_array
203
+
199
204
200
205
def _get_properties (schema_folder ):
201
206
# in array elements, the properties are under "items"
@@ -221,15 +226,20 @@ def _get_folder_names(schema_properties):
221
226
return folder_names
222
227
223
228
224
- def _print_indent (msg , level = 1 ):
229
+ def _print_indent (msg , level = 1 , first_in_list_object = False ):
225
230
"""
226
231
Print a message at the specified indent level.
227
232
:param msg: the message to be printed
228
233
:param level: the indent level
234
+ :param first_in_list_object: True if this is the first property of an object in a list
229
235
"""
230
236
result = ''
231
237
i = 0
232
238
while i < level :
233
239
result += ' '
234
240
i += 1
241
+
242
+ if first_in_list_object :
243
+ result = result [:- 2 ] + "- "
244
+
235
245
print '%s%s' % (result , msg )
0 commit comments