Skip to content

Commit a5d6c35

Browse files
authored
[Documentation][zos_lineinfile] Add and standarize docstrings on modules/zos_lineinfile.py (#1355)
* Add and standarize docstrings on modules/zos_lineinfile.py * Create changelog fragment * Modify google style to numpy
1 parent fdcbf56 commit a5d6c35

File tree

2 files changed

+98
-42
lines changed

2 files changed

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

plugins/modules/zos_lineinfile.py

Lines changed: 95 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -295,33 +295,45 @@
295295

296296

297297
def present(src, line, regexp, ins_aft, ins_bef, encoding, first_match, backrefs, force):
298-
"""Replace a line with the matching regex pattern
299-
Insert a line before/after the matching pattern
300-
Insert a line at BOF/EOF
301-
302-
Arguments:
303-
src: {str} -- The z/OS USS file or data set to modify.
304-
line: {str} -- The line to insert/replace into the src.
305-
regexp: {str} -- The regular expression to look for in every line of the src.
306-
If regexp matches, ins_aft/ins_bef will be ignored.
307-
ins_aft: {str} -- Insert the line after matching '*regex*' pattern or EOF.
308-
choices:
309-
- EOF
310-
- '*regex*'
311-
ins_bef: {str} -- Insert the line before matching '*regex*' pattern or BOF.
312-
choices:
313-
- BOF
314-
- '*regex*'
315-
encoding: {str} -- Encoding of the src.
316-
first_match: {bool} -- Take the first matching regex pattern.
317-
backrefs: {bool} -- Back reference
318-
force: {bool} -- force for modify a member part of a task in execution
319-
320-
Returns:
321-
str -- Information in JSON format. keys:
322-
cmd: {str} -- dsed shell command
323-
found: {int} -- Number of matching regex pattern
324-
changed: {bool} -- Indicates if the source was modified.
298+
"""Replace a line with the matching regex pattern.
299+
Insert a line before/after the matching pattern.
300+
Insert a line at BOF/EOF.
301+
302+
Parameters
303+
----------
304+
src : str
305+
The z/OS USS file or data set to modify.
306+
line : str
307+
The line to insert/replace into the src.
308+
regexp : str
309+
The regular expression to look for in every line of the src.
310+
If regexp matches, ins_aft/ins_bef will be ignored.
311+
ins_aft : str
312+
Insert the line after matching '*regex*' pattern or EOF.
313+
choices:
314+
- EOF
315+
- '*regex*'
316+
ins_bef : str
317+
Insert the line before matching '*regex*' pattern or BOF.
318+
choices:
319+
- BOF
320+
- '*regex*'
321+
encoding : str
322+
Encoding of the src.
323+
first_match : bool
324+
Take the first matching regex pattern.
325+
backrefs : bool
326+
Back reference.
327+
force : bool
328+
force for modify a member part of a task in execution.
329+
330+
Returns
331+
-------
332+
str
333+
Information in JSON format. keys:
334+
cmd {str} -- dsed shell command
335+
found {int} -- Number of matching regex pattern
336+
changed {bool} -- Indicates if the source was modified.
325337
"""
326338
return datasets.lineinfile(
327339
src,
@@ -339,33 +351,74 @@ def present(src, line, regexp, ins_aft, ins_bef, encoding, first_match, backrefs
339351

340352

341353
def absent(src, line, regexp, encoding, force):
342-
"""Delete lines with matching regex pattern
343-
344-
Arguments:
345-
src: {str} -- The z/OS USS file or data set to modify.
346-
line: {str} -- The line to be deleted in the src. If line matches,
347-
regexp will be ignored.
348-
regexp: {str} -- The regular expression to look for in every line of the src.
349-
encoding: {str} -- Encoding of the src.
350-
force: {bool} -- force for modify a member part of a task in execution
351-
352-
Returns:
353-
str -- Information in JSON format. keys:
354-
cmd: {str} -- dsed shell command
355-
found: {int} -- Number of matching regex pattern
356-
changed: {bool} -- Indicates if the source was modified.
354+
"""Delete lines with matching regex pattern.
355+
356+
Parameters
357+
----------
358+
src : str
359+
The z/OS USS file or data set to modify.
360+
line : str
361+
The line to be deleted in the src. If line matches,
362+
regexp will be ignored.
363+
regexp : str
364+
The regular expression to look for in every line of the src.
365+
encoding : str
366+
Encoding of the src.
367+
force : bool
368+
Force for modify a member part of a task in execution.
369+
370+
Returns
371+
-------
372+
str
373+
Information in JSON format. keys:
374+
cmd {str} -- dsed shell command
375+
found {int} -- Number of matching regex pattern
376+
changed {bool} -- Indicates if the source was modified.
357377
"""
358378
return datasets.lineinfile(src, line, regex=regexp, encoding=encoding, state=False, debug=True, force=force)
359379

360380

361381
def quotedString(string):
382+
"""Add escape if string was quoted.
383+
384+
Parameters
385+
----------
386+
string : str
387+
Given string.
388+
389+
Returns
390+
-------
391+
str
392+
The string with the quote marks replaced.
393+
"""
362394
# add escape if string was quoted
363395
if not isinstance(string, str):
364396
return string
365397
return string.replace('"', '\\\"')
366398

367399

368400
def main():
401+
"""Initialize the module.
402+
403+
Raises
404+
------
405+
fail_json
406+
Parameter verification failed.
407+
fail_json
408+
regexp is required with backrefs=true.
409+
fail_json
410+
line is required with state=present.
411+
fail_json
412+
One of line or regexp is required with state=absent.
413+
fail_json
414+
Source does not exist.
415+
fail_json
416+
Data set type is NOT supported.
417+
fail_json
418+
Creating backup has failed.
419+
fail_json
420+
dsed return content is NOT in json format.
421+
"""
369422
module_args = dict(
370423
src=dict(
371424
type='str',

0 commit comments

Comments
 (0)