Improve patchport
This changes the syntax of it, so please keep that in mind.
This commit is contained in:
parent
92987f5017
commit
be345da97e
3 changed files with 29 additions and 20 deletions
|
@ -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`
|
||||
|
|
1
patchport-state.json
Normal file
1
patchport-state.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"versioncode": "899", "versionname": "8.9.9"}
|
44
patchport.py
44
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.")
|
||||
|
|
Reference in a new issue