320
320
mvscmd = ZOAUImportError (traceback .format_exc ())
321
321
ztypes = ZOAUImportError (traceback .format_exc ())
322
322
323
+ try :
324
+ from zoautil_py import exceptions as zoau_exceptions
325
+ except Exception :
326
+ zoau_exceptions = ZOAUImportError (traceback .format_exc ())
327
+
323
328
324
329
class FetchHandler :
325
330
def __init__ (self , module ):
@@ -621,29 +626,37 @@ def _fetch_pdse(self, src, is_binary, temp_dir=None, encoding=None):
621
626
622
627
Raises
623
628
------
624
- fail_json
629
+ ZOSFetchError
625
630
Error copying partitioned dataset to USS.
626
631
fail_json
627
632
Error converting encoding of the member.
628
633
"""
629
634
dir_path = tempfile .mkdtemp (dir = temp_dir )
630
- cmd = "cp -B \" //'{0}'\" {1}"
631
- if not is_binary :
632
- cmd = cmd .replace (" -B" , "" )
633
- rc , out , err = self ._run_command (cmd .format (src , dir_path ))
634
- if rc != 0 :
635
+
636
+ copy_args = {
637
+ "options" : ""
638
+ }
639
+
640
+ if is_binary :
641
+ copy_args ["options" ] = "-B"
642
+
643
+ try :
644
+ datasets .copy (source = src , target = dir_path , ** copy_args )
645
+
646
+ except zoau_exceptions .ZOAUException as copy_exception :
635
647
rmtree (dir_path )
636
- self . _fail_json (
648
+ raise ZOSFetchError (
637
649
msg = (
638
650
"Error copying partitioned data set {0} to USS. Make sure it is"
639
651
" not empty" .format (src )
640
652
),
641
- stdout = out ,
642
- stderr = err ,
643
- stdout_lines = out . splitlines () ,
644
- stderr_lines = err .splitlines (),
645
- rc = rc ,
653
+ rc = copy_exception . response . rc ,
654
+ stdout = copy_exception . response . stdout_response ,
655
+ stderr = copy_exception . response . stderr_response ,
656
+ stdout_lines = copy_exception . response . stdout_response .splitlines (),
657
+ stderr_lines = copy_exception . response . stderr_response . splitlines () ,
646
658
)
659
+
647
660
if (not is_binary ) and encoding :
648
661
enc_utils = encode .EncodeUtils ()
649
662
from_code_set = encoding .get ("from" )
@@ -740,7 +753,7 @@ def _fetch_mvs_data(self, src, is_binary, temp_dir=None, file_override=None, enc
740
753
741
754
Raises
742
755
------
743
- fail_json
756
+ ZOSFetchError
744
757
Unable to copy to USS.
745
758
fail_json
746
759
Error converting encoding of the dataset.
@@ -754,22 +767,27 @@ def _fetch_mvs_data(self, src, is_binary, temp_dir=None, file_override=None, enc
754
767
fd , file_path = tempfile .mkstemp (dir = temp_dir )
755
768
os .close (fd )
756
769
757
- cmd = "cp -B \" //'{0}' \" {1}"
758
- if not is_binary :
759
- cmd = cmd . replace ( " -B" , "" )
770
+ copy_args = {
771
+ "options" : ""
772
+ }
760
773
761
- rc , out , err = self ._run_command (cmd .format (src , file_path ))
774
+ if is_binary :
775
+ copy_args ["options" ] = "-B"
762
776
763
- if rc != 0 :
777
+ try :
778
+ datasets .copy (source = src , target = file_path , ** copy_args )
779
+
780
+ except zoau_exceptions .ZOAUException as copy_exception :
764
781
os .remove (file_path )
765
- self . _fail_json (
782
+ raise ZOSFetchError (
766
783
msg = "Unable to copy {0} to USS" .format (src ),
767
- stdout = str ( out ) ,
768
- stderr = str ( err ) ,
769
- rc = rc ,
770
- stdout_lines = str ( out ) .splitlines (),
771
- stderr_lines = str ( err ) .splitlines (),
784
+ rc = copy_exception . response . rc ,
785
+ stdout = copy_exception . response . stdout_response ,
786
+ stderr = copy_exception . response . stderr_response ,
787
+ stdout_lines = copy_exception . response . stdout_response .splitlines (),
788
+ stderr_lines = copy_exception . response . stderr_response .splitlines (),
772
789
)
790
+
773
791
if (not is_binary ) and encoding :
774
792
enc_utils = encode .EncodeUtils ()
775
793
from_code_set = encoding .get ("from" )
@@ -1036,6 +1054,36 @@ def run_module():
1036
1054
module .exit_json (** res_args )
1037
1055
1038
1056
1057
+ class ZOSFetchError (Exception ):
1058
+ def __init__ (self , msg , rc = "" , stdout = "" , stderr = "" , stdout_lines = "" , stderr_lines = "" ):
1059
+ """Error in a copy operation.
1060
+
1061
+ Parameters
1062
+ ----------
1063
+ msg : str
1064
+ Human readable string describing the exception.
1065
+ rc : int
1066
+ Result code.
1067
+ stdout : str
1068
+ Standart output.
1069
+ stderr : str
1070
+ Standart error.
1071
+ stdout_lines : str
1072
+ Standart output divided in lines.
1073
+ stderr_lines : str
1074
+ Standart error divided in lines.
1075
+ """
1076
+ self .json_args = dict (
1077
+ msg = msg ,
1078
+ rc = rc ,
1079
+ stdout = stdout ,
1080
+ stderr = stderr ,
1081
+ stdout_lines = stdout_lines ,
1082
+ stderr_lines = stderr_lines ,
1083
+ )
1084
+ super ().__init__ (self .msg )
1085
+
1086
+
1039
1087
def main ():
1040
1088
run_module ()
1041
1089
0 commit comments