From be345da97e652fc235725eea8dc97e3e01579572 Mon Sep 17 00:00:00 2001 From: Ave Ozkal Date: Sat, 18 May 2019 09:54:20 +0300 Subject: [PATCH] Improve patchport This changes the syntax of it, so please keep that in mind. --- README.md | 4 ++-- patchport-state.json | 1 + patchport.py | 44 ++++++++++++++++++++++++++------------------ 3 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 patchport-state.json diff --git a/README.md b/README.md index 30007dd..12d95cb 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,6 @@ To get the diff, run `diff -crB -x "dist" -x "res/raw" -x "build" CleanFolder Pa You can use `patchport.py` to easily attempt to port patches. -It's not really intelligent and doesn't do much more than just checking if an existing patch can be applied to a given version (it also replaces relevant variables required for porting various patches), but it saves a lot of time if used carefully. +It's not really intelligent and doesn't do much more than manually preparing necessary patch, checking if an existing patch can be applied to a given version, replacing relevant variables required for porting various patches and eliminating offsets caused by updates, but it saves a lot of time if used carefully. -Example command: `python3 patchport.py 839 8.3.9g /home/ave/Downloads/dic/com.discord-841 /home/ave/Projects/cutthecord/` +Example command: `python3 patchport.py /home/ave/Downloads/dic/com.discord-841` diff --git a/patchport-state.json b/patchport-state.json new file mode 100644 index 0000000..d34c7bc --- /dev/null +++ b/patchport-state.json @@ -0,0 +1 @@ +{"versioncode": "899", "versionname": "8.9.9"} diff --git a/patchport.py b/patchport.py index c256eff..d67518b 100644 --- a/patchport.py +++ b/patchport.py @@ -2,17 +2,21 @@ import re import sys import os +import json import subprocess import datetime import shutil # Example invocation: -# python3 patchport.py 839 8.3.9g /home/ave/apks/com.discord-841/ /home/ave/cutthecordrepo/ +# python3 patchport.py /home/ave/apks/com.discord-900/ -from_versioncode = sys.argv[1] -from_versionname = sys.argv[2] -apk_folder = sys.argv[3] -cutthecord_folder = sys.argv[4] +with open("patchport-state.json", "r") as f: + jin = json.load(f) + from_versioncode = jin["versioncode"] + from_versionname = jin["versionname"] + +apk_folder = sys.argv[1] +cutthecord_folder = os.path.dirname(os.path.realpath(__file__)) debug = False tmp_folder = "/tmp/patchport" @@ -167,20 +171,24 @@ for patch in os.listdir(os.path.join(cutthecord_folder, "patches")): if not out_path.endswith("-failed"): print(f"PORTED: {patch} was successfully ported.") +ctcreadme_path = os.path.join(cutthecord_folder, "README.md") +# TODO: can we pull the correct date from distok? +out_datestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d") +# Update readme with latest version, hacky +# https://stackoverflow.com/a/35130508/3286892 +with open(ctcreadme_path, 'r') as f: + ctcr_text = f.read().replace(f'{from_versionname} ({from_versioncode})', + f'{to_versionname} ({to_versioncode})') +in_datestamp = re_releasedate.findall(ctcr_text)[0] +ctcr_text = ctcr_text.replace(in_datestamp, out_datestamp) +with open(ctcreadme_path, "w") as f: + f.write(ctcr_text) + +with open("patchport-state.json", "w") as f: + jout = {"versionname": to_versionname, "versioncode": to_versioncode} + json.dump(jout, f) + if failures: print(f"Port complete. Following patches failed: {', '.join(failures)}") else: - ctcreadme_path = os.path.join(cutthecord_folder, "README.md") - # TODO: can we pull the correct date from distok? - out_datestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d") - # Update readme with latest version, hacky - # https://stackoverflow.com/a/35130508/3286892 - with open(ctcreadme_path, 'r') as f: - ctcr_text = f.read().replace(f'{from_versionname} ({from_versioncode})', - f'{to_versionname} ({to_versioncode})') - in_datestamp = re_releasedate.findall(ctcr_text)[0] - ctcr_text = ctcr_text.replace(in_datestamp, out_datestamp) - with open(ctcreadme_path, "w") as f: - f.write(ctcr_text) - print("Port complete. All patches completed successfully.")