forked from distok/cutthecord
		
	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.
 | 
					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 re
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
import datetime
 | 
					import datetime
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Example invocation:
 | 
					# 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]
 | 
					with open("patchport-state.json", "r") as f:
 | 
				
			||||||
from_versionname = sys.argv[2]
 | 
					    jin = json.load(f)
 | 
				
			||||||
apk_folder = sys.argv[3]
 | 
					    from_versioncode = jin["versioncode"]
 | 
				
			||||||
cutthecord_folder = sys.argv[4]
 | 
					    from_versionname = jin["versionname"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					apk_folder = sys.argv[1]
 | 
				
			||||||
 | 
					cutthecord_folder = os.path.dirname(os.path.realpath(__file__))
 | 
				
			||||||
debug = False
 | 
					debug = False
 | 
				
			||||||
tmp_folder = "/tmp/patchport"
 | 
					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"):
 | 
					    if not out_path.endswith("-failed"):
 | 
				
			||||||
        print(f"PORTED: {patch} was successfully ported.")
 | 
					        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:
 | 
					if failures:
 | 
				
			||||||
    print(f"Port complete. Following patches failed: {', '.join(failures)}")
 | 
					    print(f"Port complete. Following patches failed: {', '.join(failures)}")
 | 
				
			||||||
else:
 | 
					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.")
 | 
					    print("Port complete. All patches completed successfully.")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue