331
331
- The destination I(dest) character set for the files to be written as.
332
332
required: false
333
333
type: str
334
+ skip_encoding:
335
+ description:
336
+ - List of names to skip encoding before archiving. This is only used if I(encoding) is set, otherwise is ignored.
337
+ required: false
338
+ type: list
339
+ elements: str
334
340
attributes:
335
341
action:
336
342
support: none
438
444
encoding:
439
445
from: IBM-1047
440
446
to: ISO8859-1
447
+
448
+ - name: Encode and archive multiple data sets but skip encoding for a few.
449
+ zos_archive:
450
+ src:
451
+ - "USER.ARCHIVE1.TEST"
452
+ - "USER.ARCHIVE2.TEST"
453
+ dest: "USER.ARCHIVE.RESULT.TRS"
454
+ format:
455
+ name: terse
456
+ format_options:
457
+ use_adrdssu: true
458
+ encoding:
459
+ from: IBM-1047
460
+ to: ISO8859-1
461
+ skip_encoding:
462
+ - "USER.ARCHIVE2.TEST"
441
463
'''
442
464
443
465
RETURN = r'''
484
506
description: The list of matching exclude paths from the exclude option.
485
507
type: list
486
508
returned: always
509
+ encoded:
510
+ description:
511
+ List of files or data sets that were successfully encoded.
512
+ type: list
513
+ returned: success
514
+ failed_on_encoding:
515
+ description:
516
+ List of files or data sets that were failed while encoding.
517
+ type: list
518
+ returned: success
519
+ skipped_encoding_targets:
520
+ description:
521
+ List of files or data sets that were skipped while encoding.
522
+ type: list
523
+ returned: success
487
524
'''
488
525
489
526
import abc
@@ -652,6 +689,14 @@ def __init__(self, module):
652
689
The state of the input C(src).
653
690
xmit_log_data_set : str
654
691
The name of the data set to store xmit log output.
692
+ skip_encoding : list[str]
693
+ List of paths to exclude in encoding.
694
+ from_encoding: str
695
+ The encoding of the source file.
696
+ to_encoding : str
697
+ The required encoding of the destination file.
698
+ skipped_encoding_targets : list[str]
699
+ List of paths to exclude in encoding return value.
655
700
656
701
"""
657
702
self .module = module
@@ -675,6 +720,11 @@ def __init__(self, module):
675
720
encoding_param = module .params .get ("encoding" ) or {}
676
721
self .from_encoding = encoding_param .get ("from" )
677
722
self .to_encoding = encoding_param .get ("to" )
723
+ self .encoded = list ()
724
+ self .failed_on_encoding = list ()
725
+ self .skip_encoding = encoding_param .get ("skip_encoding" )
726
+ self .skipped_encoding_targets = ""
727
+ self .encode_targets = []
678
728
679
729
def targets_exist (self ):
680
730
"""Returns if there are targets or not.
@@ -702,6 +752,10 @@ def update_permissions(self):
702
752
def find_targets (self ):
703
753
pass
704
754
755
+ @abc .abstractmethod
756
+ def encoding_targets (self ):
757
+ pass
758
+
705
759
@abc .abstractmethod
706
760
def _get_checksums (self , src ):
707
761
pass
@@ -746,6 +800,9 @@ def result(self):
746
800
'expanded_sources' : list (self .expanded_sources ),
747
801
'expanded_exclude_sources' : list (self .expanded_exclude_sources ),
748
802
'xmit_log_data_set' : self .xmit_log_data_set ,
803
+ 'encoded' : getattr (self , 'encoded' ),
804
+ 'failed_on_encoding' : getattr (self , 'failed_on_encoding' ),
805
+ 'skipped_encoding_targets' : getattr (self , 'skipped_encoding_targets' ),
749
806
}
750
807
751
808
@@ -818,6 +875,17 @@ def find_targets(self):
818
875
else :
819
876
self .not_found .append (path )
820
877
878
+ def encoding_targets (self ):
879
+ """Finds encoding target files in host.
880
+ """
881
+ if self .skip_encoding :
882
+ self .encode_targets = [
883
+ path for path in self .targets if path not in self .skip_encoding
884
+ ]
885
+ self .skipped_encoding_targets = self .skip_encoding
886
+ else :
887
+ self .encode_targets = self .targets
888
+
821
889
def _get_checksums (self , src ):
822
890
"""Calculate SHA256 hash for a given file.
823
891
@@ -950,18 +1018,32 @@ def get_state(self):
950
1018
951
1019
def encode_source (self ):
952
1020
"""Convert encoding for given src
1021
+ Returns
1022
+ -------
1023
+ Union
1024
+ encoded, failed_on_encoding or skipped_encoding list
953
1025
"""
954
1026
enc_utils = encode .EncodeUtils ()
955
- try :
956
- for target in self .targets :
1027
+ self .encoded = []
1028
+ self .failed_on_encoding = []
1029
+
1030
+ for target in self .encode_targets :
1031
+ try :
957
1032
convert_rc = enc_utils .uss_convert_encoding_prev (
958
1033
target , target , self .from_encoding , self .to_encoding
959
1034
)
960
1035
if convert_rc :
961
1036
enc_utils .uss_tag_encoding (target , self .to_encoding )
1037
+ self .encoded .append (os .path .abspath (target ))
962
1038
963
- except Exception as e :
964
- raise EncodeError ("Failed to encode in the required codeset: {e}" ) from e
1039
+ except Exception :
1040
+ self .failed_on_encoding .append (os .path .abspath (target ))
1041
+
1042
+ return {
1043
+ "encoded" : self .encoded ,
1044
+ "failed_on_encoding" : self .failed_on_encoding ,
1045
+ "skipped_encoding_targets" : self .skipped_encoding_targets
1046
+ }
965
1047
966
1048
967
1049
class TarArchive (USSArchive ):
@@ -1114,6 +1196,17 @@ def find_targets(self):
1114
1196
else :
1115
1197
self .not_found .append (path )
1116
1198
1199
+ def encoding_targets (self ):
1200
+ """Finds encoding target datasets in host.
1201
+ """
1202
+ if self .skip_encoding :
1203
+ self .encode_targets = [
1204
+ path for path in self .targets if path not in self .skip_encoding
1205
+ ]
1206
+ self .skipped_encoding_targets = self .skip_encoding
1207
+ else :
1208
+ self .encode_targets = self .targets
1209
+
1117
1210
def _create_dest_data_set (
1118
1211
self ,
1119
1212
name = None ,
@@ -1431,11 +1524,16 @@ def compute_dest_size(self):
1431
1524
1432
1525
def encode_source (self ):
1433
1526
"""Convert encoding for given src
1527
+ Returns
1528
+ -------
1529
+ Union
1530
+ encoded, failed_on_encoding or skipped_encoding list
1434
1531
"""
1435
1532
enc_utils = encode .EncodeUtils ()
1436
-
1437
- try :
1438
- for target in self .targets :
1533
+ self .encoded = []
1534
+ self .failed_on_encoding = []
1535
+ for target in self .encode_targets :
1536
+ try :
1439
1537
ds_type = data_set .DataSetUtils (target , tmphlq = self .tmphlq ).ds_type ()
1440
1538
if not ds_type :
1441
1539
raise EncodeError ("Unable to determine data set type of {0}" .format (target ))
@@ -1448,8 +1546,14 @@ def encode_source(self):
1448
1546
dest_type = ds_type ,
1449
1547
tmphlq = self .tmphlq
1450
1548
)
1451
- except Exception as e :
1452
- raise EncodeError (f"Failed to encode in the required codeset: { e } " ) from e
1549
+ self .encoded .append (os .path .abspath (target ))
1550
+ except Exception :
1551
+ self .failed_on_encoding .append (os .path .abspath (target ))
1552
+ return {
1553
+ "encoded" : self .encoded ,
1554
+ "failed_on_encoding" : self .failed_on_encoding ,
1555
+ "skipped_encoding_targets" : self .skipped_encoding_targets
1556
+ }
1453
1557
1454
1558
1455
1559
class AMATerseArchive (MVSArchive ):
@@ -1795,6 +1899,11 @@ def run_module():
1795
1899
"to" : dict (
1796
1900
type = 'str' ,
1797
1901
required = False ,
1902
+ ),
1903
+ "skip_encoding" : dict (
1904
+ type = 'list' ,
1905
+ elements = 'str' ,
1906
+ required = False ,
1798
1907
)
1799
1908
}
1800
1909
)
@@ -1877,7 +1986,8 @@ def run_module():
1877
1986
type = 'dict' ,
1878
1987
options = {
1879
1988
'from' : dict (type = 'str' ),
1880
- "to" : dict (type = 'str' )
1989
+ 'to' : dict (type = 'str' ),
1990
+ 'skip_encoding' : dict (type = 'list' , elements = 'str' , required = False ),
1881
1991
}
1882
1992
)
1883
1993
)
@@ -1906,7 +2016,13 @@ def run_module():
1906
2016
archive .find_targets ()
1907
2017
if archive .targets_exist ():
1908
2018
if encoding :
1909
- archive .encode_source ()
2019
+ archive .encoding_targets ()
2020
+ encoding_result = archive .encode_source ()
2021
+ archive .result .update ({
2022
+ "encoded" : encoding_result .get ("encoded" , []),
2023
+ "failed_on_encoding" : encoding_result .get ("failed_on_encoding" , []),
2024
+ "skipped_encoding_targets" : encoding_result .get ("skipped_encoding_targets" , [])
2025
+ })
1910
2026
archive .compute_dest_size ()
1911
2027
archive .archive_targets ()
1912
2028
if archive .remove :
0 commit comments