Skip to content

Commit 6499a81

Browse files
IsaacVReyrichp405fernandofloresg
authored
[Documentation][zos_blockinline] Standarize and add docstrings on modules/zos_blockinline.py (#1343)
* Standarize doc-strings on modules/zos_blockinline.py * Add a docstring on modules/zos_blockinline.quotedString() * Create changelog fragment * Modify google style to numpy * Standarize numpy style * Update zos_blockinfile.py added blank line at 457 to address pep8 error --------- Co-authored-by: Rich Parker <[email protected]> Co-authored-by: Fernando Flores <[email protected]>
1 parent dd8f23d commit 6499a81

File tree

2 files changed

+103
-40
lines changed

2 files changed

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

plugins/modules/zos_blockinfile.py

Lines changed: 100 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,21 @@
344344

345345

346346
def transformBlock(block, indentation_char, indentation_spaces):
347-
"""Prepends the specified number of spaces to the block in all lines
348-
Arguments:
349-
block: {str} -- The block text to be transformed.
350-
indentation_char: {str} -- The indentation char to be used.
351-
indentation_spaces: {int} -- Number of times the indentation char to prepend.
352-
Returns:
353-
block: {str} -- The text block after applying the necessary transformations.
347+
"""Prepends the specified number of spaces to the block in all lines.
348+
349+
Parameters
350+
----------
351+
block : str
352+
The block text to be transformed.
353+
indentation_char : str
354+
The indentation char to be used.
355+
indentation_spaces : int
356+
Number of times the indentation char to prepend.
357+
358+
Returns
359+
-------
360+
str
361+
The text block after applying the necessary transformations.
354362
"""
355363
blocklines = block.splitlines()
356364
# Prepend spaces transformation
@@ -364,50 +372,83 @@ def transformBlock(block, indentation_char, indentation_spaces):
364372

365373

366374
def present(src, block, marker, ins_aft, ins_bef, encoding, force):
367-
"""Replace a block with the matching regex pattern
368-
Insert a block before/after the matching pattern
369-
Insert a block at BOF/EOF
370-
Arguments:
371-
src: {str} -- The z/OS USS file or data set to modify.
372-
block: {str} -- The block to insert/replace into the src.
373-
marker: {str} -- The block will be inserted/updated with the markers.
374-
ins_aft: {str} -- Insert the block after matching '*regex*' pattern or EOF.
375-
choices:
376-
- EOF
377-
- '*regex*'
378-
ins_bef: {str} -- Insert the block before matching '*regex*' pattern or BOF.
379-
choices:
380-
- BOF
381-
- '*regex*'
382-
encoding: {str} -- Encoding of the src.
383-
force: {bool} -- If not empty passes True option to dmod cmd.
384-
Returns:
385-
str -- Information in JSON format. keys:
386-
cmd: {str} -- dmod shell command
387-
found: {int} -- Number of matching regex pattern
388-
changed: {bool} -- Indicates if the destination was modified.
375+
"""Replace a block with the matching regex pattern.
376+
Insert a block before/after the matching pattern.
377+
Insert a block at BOF/EOF.
378+
379+
Parameters
380+
----------
381+
src : str
382+
The z/OS USS file or data set to modify.
383+
block : str
384+
The block to insert/replace into the src.
385+
marker : str
386+
The block will be inserted/updated with the markers.
387+
ins_aft : str
388+
Insert the block after matching '*regex*' pattern or EOF.
389+
choices:
390+
- EOF
391+
- '*regex*'
392+
ins_bef : str
393+
Insert the block before matching '*regex*' pattern or BOF.
394+
choices:
395+
- BOF
396+
- '*regex*'
397+
encoding : str
398+
Encoding of the src.
399+
force : bool
400+
If not empty passes True option to dmod cmd.
401+
402+
Returns
403+
-------
404+
str
405+
Information in JSON format. keys:
406+
cmd {str} -- dmod shell command.
407+
found {int} -- Number of matching regex pattern.
408+
changed {bool} -- Indicates if the destination was modified.
389409
"""
390410
return datasets.blockinfile(src, True, block=block, marker=marker, insert_after=ins_aft,
391411
insert_before=ins_bef, encoding=encoding, force=force, as_json=True)
392412

393413

394414
def absent(src, marker, encoding, force):
395-
"""Delete blocks with matching regex pattern
396-
Arguments:
397-
src: {str} -- The z/OS USS file or data set to modify.
398-
marker: {str} -- Identifies the block to be removed.
399-
encoding: {str} -- Encoding of the src.
400-
force: {bool} -- If not empty passes the value True option to dmod cmd.
401-
Returns:
402-
str -- Information in JSON format. keys:
403-
cmd: {str} -- dmod shell command
404-
found: {int} -- Number of matching regex pattern
405-
changed: {bool} -- Indicates if the destination was modified.
415+
"""Delete blocks with matching regex pattern.
416+
417+
Parameter
418+
---------
419+
src : str
420+
The z/OS USS file or data set to modify.
421+
marker : str
422+
Identifies the block to be removed.
423+
encoding : str
424+
Encoding of the src.
425+
force : bool
426+
If not empty passes the value True option to dmod cmd.
427+
428+
Returns
429+
-------
430+
str
431+
Information in JSON format. keys:
432+
cmd {str} -- dmod shell command.
433+
found {int} -- Number of matching regex pattern.
434+
changed {bool} -- Indicates if the destination was modified.
406435
"""
407436
return datasets.blockinfile(src, False, marker=marker, encoding=encoding, force=force, as_json=True)
408437

409438

410439
def quotedString(string):
440+
"""Deletes the quote mark on strings.
441+
442+
Parameters
443+
----------
444+
string : str
445+
String to delete quote marks from.
446+
447+
Returns
448+
-------
449+
str
450+
String without the quote marks.
451+
"""
411452
# add escape if string was quoted
412453
if not isinstance(string, str):
413454
return string
@@ -482,6 +523,25 @@ def clean_command(cmd):
482523

483524

484525
def main():
526+
"""Run the zos_blockinfile module core functions.
527+
528+
Raises
529+
------
530+
fail_json
531+
Parameter verification failed.
532+
fail_json
533+
Block is required with state=present.
534+
fail_json
535+
Marker should have {mark}.
536+
fail_json
537+
src does NOT exist.
538+
fail_json
539+
Data set type is NOT supported.
540+
fail_json
541+
Unable to allocate backup.
542+
fail_json
543+
ZOAU dmod return content is NOT in json format.
544+
"""
485545
module = AnsibleModule(
486546
argument_spec=dict(
487547
src=dict(

0 commit comments

Comments
 (0)