|
40 | 40 | parser = argparse.ArgumentParser(description="Updates jdks.labsjdk-ce-latest.version and jdks.labsjdk-ee-latest.version values in common.json.") |
41 | 41 | parser.add_argument("labsjdk_versions", action="store", help="URL or path to file from which labsjdk versions will be read. " \ |
42 | 42 | "The content must be a JSON object with ce and ee fields that specify the new values.") |
43 | | - parser.add_argument("common_json", action="store", help="common.json file to process") |
| 43 | + parser.add_argument("common.json", action="store", nargs="+", help="path to a common.json file to process") |
44 | 44 |
|
45 | 45 | args = parser.parse_args() |
46 | 46 |
|
47 | | - common_json_path = Path(args.common_json) |
48 | | - common_json_text = common_json_path.read_text() |
49 | | - common_json = json.loads(common_json_text) |
50 | | - ce_version = common_json["jdks"]["labsjdk-ce-latest"]["version"] |
51 | | - ee_version = common_json["jdks"]["labsjdk-ee-latest"]["version"] |
52 | | - |
53 | 47 | if args.labsjdk_versions.startswith("http://") or args.labsjdk_versions.startswith("https://"): |
54 | 48 | from urllib import request |
55 | 49 | url = args.labsjdk_versions |
|
70 | 64 | new_versions = new_versions[0:1024] + "... (truncated)" |
71 | 65 | raise SystemExit(f"Error decoding content of size {size} from {args.labsjdk_versions} as JSON: {e}\nContent:\n{new_versions}") |
72 | 66 |
|
73 | | - try: |
74 | | - new_common_json_text = common_json_text\ |
75 | | - .replace(ce_version, new_versions["ce"])\ |
76 | | - .replace(ee_version, new_versions["ee"]) |
77 | | - except KeyError as e: |
78 | | - raise SystemExit(f"Error extracting versions from JSON in {args.labsjdk_versions}: Missing value for {e}\nJSON:\n{json.dumps(new_versions, indent=2)}") |
79 | | - |
80 | | - if new_common_json_text == common_json_text: |
81 | | - print(f"No change to {common_json_path}") |
82 | | - else: |
83 | | - patch = "\n".join((line for line in difflib.unified_diff( |
84 | | - common_json_text.split("\n"), |
85 | | - new_common_json_text.split("\n"), |
86 | | - fromfile=f"a/{common_json_path.name}", |
87 | | - tofile=f"b/{common_json_path.name}", |
88 | | - lineterm="" |
89 | | - ))) |
90 | | - print(f"Updated {common_json_path} with this patch:\n{patch}") |
91 | | - common_json_path.write_text(new_common_json_text) |
| 67 | + for common_json_path in getattr(args, "common.json"): |
| 68 | + common_json_path = Path(common_json_path) |
| 69 | + common_json_text = common_json_path.read_text() |
| 70 | + common_json = json.loads(common_json_text) |
| 71 | + ce_version = common_json["jdks"]["labsjdk-ce-latest"]["version"] |
| 72 | + ee_version = common_json["jdks"]["labsjdk-ee-latest"]["version"] |
| 73 | + |
| 74 | + try: |
| 75 | + new_common_json_text = common_json_text\ |
| 76 | + .replace(ce_version, new_versions["ce"])\ |
| 77 | + .replace(ee_version, new_versions["ee"]) |
| 78 | + except KeyError as e: |
| 79 | + raise SystemExit(f"Error extracting versions from JSON in {args.labsjdk_versions}: Missing value for {e}\nJSON:\n{json.dumps(new_versions, indent=2)}") |
| 80 | + |
| 81 | + if new_common_json_text == common_json_text: |
| 82 | + print(f"No change to {common_json_path}") |
| 83 | + else: |
| 84 | + patch = "\n".join((line for line in difflib.unified_diff( |
| 85 | + common_json_text.split("\n"), |
| 86 | + new_common_json_text.split("\n"), |
| 87 | + fromfile=f"a/{common_json_path.name}", |
| 88 | + tofile=f"b/{common_json_path.name}", |
| 89 | + lineterm="" |
| 90 | + ))) |
| 91 | + print(f"Updated {common_json_path} with this patch:\n{patch}") |
| 92 | + common_json_path.write_text(new_common_json_text) |
0 commit comments