diff options
author | Sainnhe Park | 2023-08-13 21:01:02 +0800 |
---|---|---|
committer | Sainnhe Park | 2023-08-13 21:01:02 +0800 |
commit | dd35b42b1e2649f379d0a9265b3570a665f23899 (patch) | |
tree | f8a2e93295639e1c4539b445249b8764925c34d3 /patch.py | |
parent | f286760db32adbb27db9459c3b319386f287905a (diff) | |
download | aur-dd35b42b1e2649f379d0a9265b3570a665f23899.tar.gz |
Update to 1.81.1
Diffstat (limited to 'patch.py')
-rwxr-xr-x | patch.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/patch.py b/patch.py new file mode 100755 index 000000000000..8e0cb7665ee8 --- /dev/null +++ b/patch.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +import sys +import json +import os + +pkt_name = sys.argv[1] +operation = sys.argv[2] + +product_path = "/usr/lib/code/product.json" +patch_path = "/usr/share/%s/patch.json" % pkt_name +cache_path = "/usr/share/%s/cache.json" % pkt_name + +if not os.path.exists(cache_path): + with open(cache_path, 'w') as file: + file.write("{}") + +def patch(): + with open(product_path, "r") as product_file: + product_data = json.load(product_file) + with open(patch_path, "r") as patch_file: + patch_data = json.load(patch_file) + cache_data = {} + for key in patch_data.keys(): + if key in product_data: + cache_data[key] = product_data[key] + product_data[key] = patch_data[key] + with open(product_path, "w") as product_file: + json.dump(product_data, product_file, indent='\t') + with open(cache_path, "w") as cache_file: + json.dump(cache_data, cache_file, indent='\t') + +def restore(): + with open(product_path, "r") as product_file: + product_data = json.load(product_file) + with open(patch_path, "r") as patch_file: + patch_data = json.load(patch_file) + with open(cache_path, "r") as cache_file: + cache_data = json.load(cache_file) + for key in patch_data.keys(): + if key in product_data: + del product_data[key] + for key in cache_data.keys(): + product_data[key] = cache_data[key] + with open(product_path, "w") as product_file: + json.dump(product_data, product_file, indent='\t') + +if operation == "patch": + patch() +elif operation == "restore": + restore() |