Skip to content

Commit dd94cb2

Browse files
authored
[Documentation][vtoc] Add docstrings to module_utils/vtoc.py (#1337)
* Add docstrings to module_utils/vtoc.py * Create changelog fragment * Modify google style to numpy * Standarize numpy style
1 parent 7159850 commit dd94cb2

File tree

2 files changed

+167
-79
lines changed

2 files changed

+167
-79
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trivial:
2+
- vtoc - Updated docstrings to numpy style for visual aid to developers.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/1337).

plugins/module_utils/vtoc.py

Lines changed: 164 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@ def get_volume_entry(volume):
2424
"""Retrieve VTOC information for all data sets with entries
2525
on the volume.
2626
27-
Arguments:
28-
volume {str} -- The name of the volume.
29-
30-
Raises:
31-
VolumeTableOfContentsError: When any exception is raised during VTOC operations.
32-
33-
Returns:
34-
list[dict] -- List of dictionaries holding data set information from VTOC.
27+
Parameters
28+
----------
29+
volume : str
30+
The name of the volume.
31+
32+
Returns
33+
-------
34+
Union[dict]
35+
List of dictionaries holding data set information from VTOC.
36+
37+
Raises
38+
------
39+
VolumeTableOfContentsError
40+
When any exception is raised during VTOC operations.
3541
"""
3642
try:
3743
stdin = " LISTVTOC FORMAT,VOL=3390={0}".format(volume.upper())
@@ -50,12 +56,17 @@ def get_data_set_entry(data_set_name, volume):
5056
"""Retrieve VTOC information for a single data set
5157
on a volume.
5258
53-
Arguments:
54-
data_set_name {str} -- The name of the data set to retrieve information for.
55-
volume {str} -- The name of the volume.
56-
57-
Returns:
58-
dict -- The information for the data set found in VTOC.
59+
Parameters
60+
----------
61+
data_set_name : str
62+
The name of the data set to retrieve information for.
63+
volume : str
64+
The name of the volume.
65+
66+
Returns
67+
-------
68+
dict
69+
The information for the data set found in VTOC.
5970
"""
6071
data_set = None
6172
data_sets = get_volume_entry(volume)
@@ -72,12 +83,17 @@ def find_data_set_in_volume_output(data_set_name, data_sets):
7283
set if present. This method is useful when wanting to avoid multiple
7384
IEHLIST calls.
7485
75-
Arguments:
76-
data_set_name {str} -- The name of the data set to retrieve information for.
77-
data_sets {list[dict]} -- List of dictionaries holding data set information from VTOC.
78-
79-
Returns:
80-
dict -- The information for the data set found in VTOC.
86+
Parameters
87+
----------
88+
data_set_name : str
89+
The name of the data set to retrieve information for.
90+
data_sets : list[dict]
91+
List of dictionaries holding data set information from VTOC.
92+
93+
Returns
94+
-------
95+
dict
96+
The information for the data set found in VTOC.
8197
"""
8298
if isinstance(data_sets, list):
8399
for data_set in data_sets:
@@ -89,12 +105,17 @@ def find_data_set_in_volume_output(data_set_name, data_sets):
89105
def _iehlist(dd, stdin):
90106
"""Calls IEHLIST program.
91107
92-
Arguments:
93-
dd {str} -- Volume information to pass as DD statement.
94-
stdin {str} -- Input to stdin.
95-
96-
Returns:
97-
str -- The sysprint response of IEHLIST.
108+
Parameters
109+
----------
110+
dd : str
111+
Volume information to pass as DD statement.
112+
stdin : str
113+
Input to stdin.
114+
115+
Returns
116+
-------
117+
str
118+
The sysprint response of IEHLIST.
98119
"""
99120
module = AnsibleModuleHelper(argument_spec={})
100121
response = None
@@ -110,11 +131,15 @@ def _iehlist(dd, stdin):
110131
def _process_output(stdout):
111132
"""Process output of LISTVTOC.
112133
113-
Arguments:
114-
stdout {str} -- The output of LISTVTOC.
134+
Parameters
135+
----------
136+
stdout : str
137+
The output of LISTVTOC.
115138
116-
Returns:
117-
list[dict] -- List of dictionaries holding data set information from VTOC.
139+
Returns
140+
-------
141+
Union[dict]
142+
List of dictionaries holding data set information from VTOC.
118143
"""
119144
data_sets = []
120145
data_set_strings = _separate_data_set_sections(stdout)
@@ -126,11 +151,15 @@ def _process_output(stdout):
126151
def _separate_data_set_sections(contents):
127152
"""Split LISTVTOC output into data set sections.
128153
129-
Arguments:
130-
contents {str} -- The output of LISTVTOC.
154+
Parameters
155+
----------
156+
contents : str
157+
The output of LISTVTOC.
131158
132-
Returns:
133-
list[str] -- LISTVTOC output separated into sections by data set.
159+
Returns
160+
-------
161+
Union[str]
162+
LISTVTOC output separated into sections by data set.
134163
"""
135164
delimeter = "0---------------DATA SET NAME----------------"
136165
data_sets = re.split(delimeter, contents)
@@ -142,11 +171,15 @@ def _parse_data_set_info(data_set_string):
142171
"""Build dictionaries representing data set information
143172
from LISTVTOC output.
144173
145-
Arguments:
146-
data_set_string {str} -- Single data set section of the LISTVTOC output.
174+
Parameters
175+
----------
176+
data_set_string : str
177+
Single data set section of the LISTVTOC output.
147178
148-
Returns:
149-
dict -- Holds data set information from VTOC.
179+
Returns
180+
-------
181+
dict
182+
Holds data set information from VTOC.
150183
"""
151184
lines = data_set_string.split("\n")
152185
data_set_info = {}
@@ -172,13 +205,19 @@ def _parse_table_row(regex, header_row, data_row):
172205
"""Parse out a single row of VTOC table information from
173206
VTOCLIST output.
174207
175-
Arguments:
176-
regex {str} -- The regular expression used to parse table row.
177-
header_row {str} -- The row of the table containing headers.
178-
data_row {str} -- The row of the table containing data.
179-
180-
Returns:
181-
dict -- Structured data for the row of the table.
208+
Parameters
209+
----------
210+
regex : str
211+
The regular expression used to parse table row.
212+
header_row : str
213+
The row of the table containing headers.
214+
data_row : str
215+
The row of the table containing data.
216+
217+
Returns
218+
-------
219+
dict
220+
Structured data for the row of the table.
182221
"""
183222
table_data = {}
184223
fields = re.findall(regex, header_row)
@@ -200,11 +239,15 @@ def _format_table_data(table_data):
200239
This includes separating and renaming fields from
201240
their original naming and style in VTOCLIST.
202241
203-
Arguments:
204-
table_data {dict} -- Structured data parsed from VTOCLIST output.
242+
Parameters
243+
----------
244+
table_data : dict
245+
Structured data parsed from VTOCLIST output.
205246
206-
Returns:
207-
dict -- Updated data.
247+
Returns
248+
-------
249+
dict
250+
Updated data.
208251
"""
209252
handlers = {
210253
"DATA SET NAME": "data_set_name",
@@ -250,13 +293,18 @@ def _format_table_data(table_data):
250293
def _format_extend(contents, formatted_table_data):
251294
"""Format the extend field from VTOCLIST.
252295
253-
Arguments:
254-
contents {str} -- Contents of the extend field from VTOCLIST.
255-
formatted_table_data {dict} -- The dictionary containing other already formatted
296+
Parameters
297+
----------
298+
contents : str
299+
Contents of the extend field from VTOCLIST.
300+
formatted_table_data : dict
301+
The dictionary containing other already formatted
256302
table data.
257303
258-
Returns:
259-
dict -- The updated formatted_table_data dictionary.
304+
Returns
305+
-------
306+
dict
307+
The updated formatted_table_data dictionary.
260308
"""
261309
matches = re.search(r"([0-9]+)(AV|BY|KB|MB)", contents)
262310
original_space_secondary = ""
@@ -280,11 +328,15 @@ def _format_extend(contents, formatted_table_data):
280328
def _format_last_blk(contents):
281329
"""Format the last blk field from VTOCLIST.
282330
283-
Arguments:
284-
contents {str} -- Contents of the last blk field from VTOCLIST.
331+
Parameters
332+
----------
333+
contents : str
334+
Contents of the last blk field from VTOCLIST.
285335
286-
Returns:
287-
dict -- Structured data parsed from last blk field contents.
336+
Returns
337+
-------
338+
dict
339+
Structured data parsed from last blk field contents.
288340
"""
289341
result = None
290342
matches = re.search(r"[ ]*([0-9]+)[ ]+([0-9]+)[ ]+([0-9]+)?", contents)
@@ -300,11 +352,15 @@ def _format_last_blk(contents):
300352
def _format_f2_or_f3(contents):
301353
"""Format the F2 or F3 field from VTOCLIST.
302354
303-
Arguments:
304-
contents {str} -- Contents of the F2 or F3 field from VTOCLIST.
355+
Parameters
356+
----------
357+
contents : str
358+
Contents of the F2 or F3 field from VTOCLIST.
305359
306-
Returns:
307-
dict -- Structured data parsed from the F2 or F3 field contents.
360+
Returns
361+
-------
362+
dict
363+
Structured data parsed from the F2 or F3 field contents.
308364
"""
309365
result = None
310366
matches = re.search(r"[ ]*([0-9]+)[ ]+([0-9]+)[ ]+([0-9]+)", contents)
@@ -319,11 +375,15 @@ def _format_f2_or_f3(contents):
319375
def _format_dscb(contents):
320376
"""Format the dscb field from VTOCLIST.
321377
322-
Arguments:
323-
contents {str} -- Contents of the dscb field from VTOCLIST.
378+
Parameters
379+
----------
380+
contents : str
381+
Contents of the dscb field from VTOCLIST.
324382
325-
Returns:
326-
dict -- Structured data parsed from the dscb field contents.
383+
Returns
384+
-------
385+
dict
386+
Structured data parsed from the dscb field contents.
327387
"""
328388
result = None
329389
matches = re.search(r"[ ]*([0-9]+)[ ]+([0-9]+)[ ]+([0-9]+)", contents)
@@ -338,13 +398,17 @@ def _format_dscb(contents):
338398
def _parse_extents(lines):
339399
"""Parse and structure extent data from VTOCLIST.
340400
341-
Arguments:
342-
contents {list[str]} -- Partial contents of single data set section
401+
Parameters
402+
----------
403+
contents : list[str]
404+
Partial contents of single data set section
343405
from VTOCLIST that will contain extent information if data set has
344406
extents.
345407
346-
Returns:
347-
list[dict] -- Structured data parsed from the extent field contents.
408+
Returns
409+
-------
410+
dict
411+
Structured data parsed from the extent field contents.
348412
"""
349413
extents = []
350414
if re.search(r"THE\sABOVE\sDATASET\sHAS\sNO\sEXTENTS", "".join(lines)):
@@ -366,13 +430,18 @@ def _parse_extents(lines):
366430
def _extent_regex_builder(indent_length, header_groups):
367431
"""Build regular expressions for parsing extent information.
368432
369-
Arguments:
370-
indent_length {int} -- The number of spaces before extent information starts.
371-
header_groups {list[tuple]} -- Captured output of header groups identified
433+
Parameters
434+
----------
435+
indent_length : int
436+
The number of spaces before extent information starts.
437+
header_groups : list[tuple]
438+
Captured output of header groups identified
372439
during VTOCLIST parsing.
373440
374-
Returns:
375-
str -- The regular expression for parsing extent information.
441+
Returns
442+
-------
443+
str
444+
The regular expression for parsing extent information.
376445
"""
377446
extent_regex = "^[ ]{{{0}}}".format(str(indent_length))
378447
for index, header_group in enumerate(header_groups):
@@ -389,11 +458,15 @@ def _extent_regex_builder(indent_length, header_groups):
389458
def _format_extent_data(extent_data):
390459
"""Format the dscb field from VTOCLIST.
391460
392-
Arguments:
393-
extent_data {list[tuple]} -- Captured output of extent data.
461+
Parameters
462+
----------
463+
extent_data : list[tuple]
464+
Captured output of extent data.
394465
395-
Returns:
396-
dict -- Structured data parsed from captured output of extent data.
466+
Returns
467+
-------
468+
Union[dict]
469+
Structured data parsed from captured output of extent data.
397470
"""
398471
extents = []
399472
flattened_extent_data = []
@@ -418,5 +491,17 @@ def _format_extent_data(extent_data):
418491

419492
class VolumeTableOfContentsError(Exception):
420493
def __init__(self, msg=""):
494+
"""Error during VTOC parsing or retrieval.
495+
496+
Parameters
497+
----------
498+
msg : str
499+
Human readable string describing the exception.
500+
501+
Attributes
502+
----------
503+
msg : str
504+
Human readable string describing the exception.
505+
"""
421506
self.msg = "An error occurred during VTOC parsing or retrieval. {0}".format(msg)
422507
super(VolumeTableOfContentsError, self).__init__(self.msg)

0 commit comments

Comments
 (0)