Skip to content

Commit 581fdb2

Browse files
[Documentation][zos_fetch] Add and standarize docstrings on modules/zos_fetch.py (#1349)
* Add and standarize docstrings on modules/zos_fetch.py * Create changelog fragment * Modify google style to numpy * Standarize numpy style * Updated docstrings --------- Co-authored-by: Fernando Flores <[email protected]>
1 parent ae24956 commit 581fdb2

File tree

2 files changed

+158
-4
lines changed

2 files changed

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

plugins/modules/zos_fetch.py

Lines changed: 155 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,16 +303,50 @@ def __init__(self, module):
303303
self.module = module
304304

305305
def _fail_json(self, **kwargs):
306-
""" Wrapper for AnsibleModule.fail_json """
306+
"""Wrapper for AnsibleModule.fail_json.
307+
308+
Parameters
309+
----------
310+
**kwargs : dict
311+
Arguments to pass to fail_json().
312+
"""
307313
self.module.fail_json(**kwargs)
308314

309315
def _run_command(self, cmd, **kwargs):
310-
""" Wrapper for AnsibleModule.run_command """
316+
"""Wrapper for AnsibleModule.run_command.
317+
318+
Parameters
319+
----------
320+
cmd : str
321+
Command to run.
322+
**kwargs : dict
323+
Arguments to pass to run_command().
324+
325+
Returns
326+
-------
327+
tuple(int,str,str)
328+
Return code, standard output and standard error.
329+
"""
311330
return self.module.run_command(cmd, **kwargs)
312331

313332
def _get_vsam_size(self, vsam):
314333
"""Invoke IDCAMS LISTCAT command to get the record length and space used.
315334
Then estimate the space used by the VSAM data set.
335+
336+
Parameters
337+
----------
338+
vsam : str
339+
VSAM data set name.
340+
341+
Returns
342+
-------
343+
tuple(int,int,int)
344+
Total size, max_recl and rec_total.
345+
346+
Raises
347+
------
348+
fail_json
349+
Unable to obtain data set information.
316350
"""
317351
space_pri = 0
318352
total_size = 0
@@ -350,7 +384,27 @@ def _get_vsam_size(self, vsam):
350384
return total_size, max_recl, rec_total
351385

352386
def _copy_vsam_to_temp_data_set(self, ds_name):
353-
""" Copy VSAM data set to a temporary sequential data set """
387+
"""Copy VSAM data set to a temporary sequential data set.
388+
389+
Parameters
390+
----------
391+
ds_name : str
392+
VSAM dataset name to be copied into a temp data set.
393+
394+
Returns
395+
-------
396+
str
397+
Temporary dataset name.
398+
399+
Raises
400+
------
401+
fail_json
402+
OS error.
403+
fail_json
404+
cmd error while copying dataset.
405+
fail_json
406+
Failed to call IDCAMS.
407+
"""
354408
mvs_rc = 0
355409
vsam_size, max_recl, rec_total = self._get_vsam_size(ds_name)
356410
# Default in case of max recl being 80 to avoid failures when fetching and empty vsam.
@@ -442,6 +496,25 @@ def _copy_vsam_to_temp_data_set(self, ds_name):
442496
def _fetch_uss_file(self, src, is_binary, encoding=None):
443497
"""Convert encoding of a USS file. Return a tuple of temporary file
444498
name containing converted data.
499+
500+
Parameters
501+
----------
502+
src : str
503+
Source of the file.
504+
is_binary : bool
505+
If is binary.
506+
encoding : str
507+
The file encoding.
508+
509+
Returns
510+
-------
511+
str
512+
File name with the converted data.
513+
514+
Raises
515+
------
516+
fail_json
517+
Any exception ocurred while converting encoding.
445518
"""
446519
file_path = None
447520
if (not is_binary) and encoding:
@@ -471,6 +544,25 @@ def _fetch_uss_file(self, src, is_binary, encoding=None):
471544
def _fetch_vsam(self, src, is_binary, encoding=None):
472545
"""Copy the contents of a VSAM to a sequential data set.
473546
Afterwards, copy that data set to a USS file.
547+
548+
Parameters
549+
----------
550+
src : str
551+
Source of the file.
552+
is_binary : bool
553+
If is binary.
554+
encoding : str
555+
The file encoding.
556+
557+
Returns
558+
-------
559+
str
560+
USS File containing the encoded content of the input data set.
561+
562+
Raises
563+
------
564+
fail_json
565+
Unable to delete temporary dataset.
474566
"""
475567
temp_ds = self._copy_vsam_to_temp_data_set(src)
476568
file_path = self._fetch_mvs_data(temp_ds, is_binary, encoding)
@@ -487,6 +579,27 @@ def _fetch_pdse(self, src, is_binary, encoding=None):
487579
"""Copy a partitioned data set to a USS directory. If the data set
488580
is not being fetched in binary mode, encoding for all members inside
489581
the data set will be converted.
582+
583+
Parameters
584+
----------
585+
src : str
586+
Source of the dataset.
587+
is_binary : bool
588+
If is binary.
589+
encoding : str
590+
The file encoding.
591+
592+
Returns
593+
-------
594+
str
595+
Directory path containing the files of the converted data set members.
596+
597+
Raises
598+
------
599+
fail_json
600+
Error copying partitioned dataset to USS.
601+
fail_json
602+
Error converting encoding of the member.
490603
"""
491604
dir_path = tempfile.mkdtemp()
492605
cmd = "cp -B \"//'{0}'\" {1}"
@@ -531,7 +644,28 @@ def _fetch_pdse(self, src, is_binary, encoding=None):
531644

532645
def _fetch_mvs_data(self, src, is_binary, encoding=None):
533646
"""Copy a sequential data set or a partitioned data set member
534-
to a USS file
647+
to a USS file.
648+
649+
Parameters
650+
----------
651+
src : str
652+
Source of the dataset.
653+
is_binary : bool
654+
If is binary.
655+
encoding : str
656+
The file encoding.
657+
658+
Returns
659+
-------
660+
str
661+
USS File containing the encoded content of the input data set.
662+
663+
Raises
664+
------
665+
fail_json
666+
Unable to copy to USS.
667+
fail_json
668+
Error converting encoding of the dataset.
535669
"""
536670
fd, file_path = tempfile.mkstemp()
537671
os.close(fd)
@@ -571,6 +705,23 @@ def _fetch_mvs_data(self, src, is_binary, encoding=None):
571705

572706

573707
def run_module():
708+
"""Runs the module.
709+
710+
Raises
711+
------
712+
fail_json
713+
When parameter verification fails.
714+
fail_json
715+
When the source does not exist or is uncataloged.
716+
fail_json
717+
When it's unable to determine dataset type.
718+
fail_json
719+
While gathering dataset information.
720+
fail_json
721+
When the data set member was not found inside a dataset.
722+
fail_json
723+
When the file does not have appropriate read permissions.
724+
"""
574725
# ********************************************************** #
575726
# Module initialization #
576727
# ********************************************************** #

0 commit comments

Comments
 (0)