@@ -303,16 +303,50 @@ def __init__(self, module):
303
303
self .module = module
304
304
305
305
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
+ """
307
313
self .module .fail_json (** kwargs )
308
314
309
315
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
+ """
311
330
return self .module .run_command (cmd , ** kwargs )
312
331
313
332
def _get_vsam_size (self , vsam ):
314
333
"""Invoke IDCAMS LISTCAT command to get the record length and space used.
315
334
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.
316
350
"""
317
351
space_pri = 0
318
352
total_size = 0
@@ -350,7 +384,27 @@ def _get_vsam_size(self, vsam):
350
384
return total_size , max_recl , rec_total
351
385
352
386
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
+ """
354
408
mvs_rc = 0
355
409
vsam_size , max_recl , rec_total = self ._get_vsam_size (ds_name )
356
410
# 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):
442
496
def _fetch_uss_file (self , src , is_binary , encoding = None ):
443
497
"""Convert encoding of a USS file. Return a tuple of temporary file
444
498
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.
445
518
"""
446
519
file_path = None
447
520
if (not is_binary ) and encoding :
@@ -471,6 +544,25 @@ def _fetch_uss_file(self, src, is_binary, encoding=None):
471
544
def _fetch_vsam (self , src , is_binary , encoding = None ):
472
545
"""Copy the contents of a VSAM to a sequential data set.
473
546
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.
474
566
"""
475
567
temp_ds = self ._copy_vsam_to_temp_data_set (src )
476
568
file_path = self ._fetch_mvs_data (temp_ds , is_binary , encoding )
@@ -487,6 +579,27 @@ def _fetch_pdse(self, src, is_binary, encoding=None):
487
579
"""Copy a partitioned data set to a USS directory. If the data set
488
580
is not being fetched in binary mode, encoding for all members inside
489
581
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.
490
603
"""
491
604
dir_path = tempfile .mkdtemp ()
492
605
cmd = "cp -B \" //'{0}'\" {1}"
@@ -531,7 +644,28 @@ def _fetch_pdse(self, src, is_binary, encoding=None):
531
644
532
645
def _fetch_mvs_data (self , src , is_binary , encoding = None ):
533
646
"""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.
535
669
"""
536
670
fd , file_path = tempfile .mkstemp ()
537
671
os .close (fd )
@@ -571,6 +705,23 @@ def _fetch_mvs_data(self, src, is_binary, encoding=None):
571
705
572
706
573
707
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
+ """
574
725
# ********************************************************** #
575
726
# Module initialization #
576
727
# ********************************************************** #
0 commit comments