344
344
345
345
346
346
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.
354
362
"""
355
363
blocklines = block .splitlines ()
356
364
# Prepend spaces transformation
@@ -364,50 +372,83 @@ def transformBlock(block, indentation_char, indentation_spaces):
364
372
365
373
366
374
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.
389
409
"""
390
410
return datasets .blockinfile (src , True , block = block , marker = marker , insert_after = ins_aft ,
391
411
insert_before = ins_bef , encoding = encoding , force = force , as_json = True )
392
412
393
413
394
414
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.
406
435
"""
407
436
return datasets .blockinfile (src , False , marker = marker , encoding = encoding , force = force , as_json = True )
408
437
409
438
410
439
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
+ """
411
452
# add escape if string was quoted
412
453
if not isinstance (string , str ):
413
454
return string
@@ -482,6 +523,25 @@ def clean_command(cmd):
482
523
483
524
484
525
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
+ """
485
545
module = AnsibleModule (
486
546
argument_spec = dict (
487
547
src = dict (
0 commit comments