2023-08-13 14:01:09 +00:00
|
|
|
#!/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
|
|
|
|
|
2024-03-02 05:01:50 +00:00
|
|
|
|
|
|
|
class term_colors:
|
|
|
|
WARNING = "\033[93m"
|
|
|
|
ENDC = "\033[0m"
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(product_path):
|
|
|
|
print(
|
|
|
|
term_colors.WARNING
|
|
|
|
+ "WARN: "
|
|
|
|
+ term_colors.ENDC
|
|
|
|
+ product_path
|
|
|
|
+ " does not exist. You need to install extra/code in the official repository to use this package. Skipping..."
|
|
|
|
)
|
|
|
|
exit(0)
|
|
|
|
|
2023-08-13 14:01:09 +00:00
|
|
|
if not os.path.exists(cache_path):
|
2024-03-02 05:01:50 +00:00
|
|
|
with open(cache_path, "w") as file:
|
2023-08-13 14:01:09 +00:00
|
|
|
file.write("{}")
|
|
|
|
|
2024-03-02 05:01:50 +00:00
|
|
|
|
2023-08-13 14:01:09 +00:00
|
|
|
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:
|
2024-03-02 05:01:50 +00:00
|
|
|
json.dump(product_data, product_file, indent="\t")
|
2023-08-13 14:01:09 +00:00
|
|
|
with open(cache_path, "w") as cache_file:
|
2024-03-02 05:01:50 +00:00
|
|
|
json.dump(cache_data, cache_file, indent="\t")
|
|
|
|
|
2023-08-13 14:01:09 +00:00
|
|
|
|
|
|
|
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:
|
2024-03-02 05:01:50 +00:00
|
|
|
json.dump(product_data, product_file, indent="\t")
|
|
|
|
|
2023-08-13 14:01:09 +00:00
|
|
|
|
|
|
|
if operation == "patch":
|
|
|
|
patch()
|
|
|
|
elif operation == "restore":
|
|
|
|
restore()
|