Created
October 21, 2020 01:09
-
-
Save t1m0thyj/d1a5eaef8081c5cd50d0cf8c8fcbd1ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""zowe_dl.py - Download all data sets matched by a wildcard | |
Usage: zowe_dl.py <dsname-wildcard> [zowe-args] | |
Examples: | |
zowe_dl.py HLQ.* --zosmf-p PROFILE | |
zowe_dl.py HLQ.* --host HOST --port PORT --user USER --password PASSWORD --no-ru | |
""" | |
import json | |
import subprocess | |
import sys | |
# Mapping of data set qualifiers to file extensions | |
ext_mapping = {"asm": "asm", "c": "c", "cntl": "jcl", "h": "h", "jcl": "jcl", "rexx": "rex"} | |
dslevel = sys.argv[1] | |
zowe_args = sys.argv[2:] | |
def zowe(args): | |
return subprocess.check_output(["zowe"] + args.split() + zowe_args, shell=True, timeout=30) | |
attrs_list = json.loads(zowe(f"files ls ds {dslevel} -a --rfj"))["data"]["apiResponse"]["items"] | |
num_datasets = len(attrs_list) | |
for i, attrs in enumerate(attrs_list): | |
dsname = attrs["dsname"] | |
print(f"Downloading '{dsname}' ({i + 1}/{num_datasets})...", end="", flush=True) | |
cmd_str = "am" if attrs.get("dsntp") == "PDS" else "ds" | |
full_cmd_str = f"files dl {cmd_str} {dsname}" | |
for qual in dsname.lower().split("."): | |
if qual in ext_mapping: | |
full_cmd_str += f" -e .{ext_mapping[qual]}" | |
break | |
try: | |
zowe(full_cmd_str) | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment