mirror of
https://github.com/daijro/camoufox.git
synced 2026-08-24 16:00:08 +00:00
Clone & patch in same local repo
Do not copy the Firefox source repo before patching. Manage everything through git instead.
This commit is contained in:
+91
-62
@@ -1,37 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
GUI for managing Camoufox patches.
|
||||
"""
|
||||
|
||||
import os
|
||||
import contextlib
|
||||
|
||||
import easygui
|
||||
from patch import list_files, patch, run
|
||||
|
||||
# Cd to the camoufox-* folder (this is located ..)
|
||||
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
folders = os.listdir('.')
|
||||
for folder in folders:
|
||||
if os.path.isdir(folder) and folder.startswith('camoufox-'):
|
||||
os.chdir(folder)
|
||||
break
|
||||
else:
|
||||
raise Exception('No camoufox-* folder found')
|
||||
|
||||
def into_camoufox_dir():
|
||||
"""Find and cd to the camoufox-* folder (this is located ..)"""
|
||||
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
folders = os.listdir('.')
|
||||
for folder in folders:
|
||||
if os.path.isdir(folder) and folder.startswith('camoufox-'):
|
||||
os.chdir(folder)
|
||||
break
|
||||
else:
|
||||
raise FileNotFoundError('No camoufox-* folder found')
|
||||
|
||||
|
||||
"""
|
||||
GUI Choicebox with the following options:
|
||||
- Reset:
|
||||
`git checkout -- .`
|
||||
then patch *.bootstrap (required)
|
||||
- Patch all BUT:
|
||||
Checklist of *.patch files in ../patches to exclude. The rest gets patched.
|
||||
- Find broken:
|
||||
Resets, runs patches, then finds broken patches.
|
||||
If all show good error code, show at the top of the message box "All patches applied successfully"
|
||||
If any show bad error code, show at the top of the message box "Some patches failed to apply", then the rej output
|
||||
"""
|
||||
@contextlib.contextmanager
|
||||
def temp_cd(path):
|
||||
# Temporarily change to a different working directory
|
||||
_old_cwd = os.getcwd()
|
||||
os.chdir(os.path.abspath(path))
|
||||
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
os.chdir(_old_cwd)
|
||||
|
||||
|
||||
def reset_camoufox():
|
||||
run('git checkout -- .')
|
||||
for patch_file in list_files('../patches', suffix='*.bootstrap'):
|
||||
patch(patch_file)
|
||||
with temp_cd('..'):
|
||||
run('make clean')
|
||||
|
||||
|
||||
def run_patches(reverse=False):
|
||||
@@ -58,49 +64,72 @@ choices = [
|
||||
"Write workspace to patch",
|
||||
]
|
||||
|
||||
choice = easygui.choicebox("Select an option:", "Camoufox Patcher", choices)
|
||||
"""
|
||||
GUI Choicebox with the following options:
|
||||
- Reset:
|
||||
`make clean`
|
||||
- Patch all BUT:
|
||||
Checklist of *.patch files in ../patches to exclude. The rest gets patched.
|
||||
- Find broken:
|
||||
Resets, runs patches, then finds broken patches.
|
||||
If all show good error code, show at the top of the message box "All patches applied successfully"
|
||||
If any show bad error code, show at the top of the message box "Some patches failed to apply", then the rej output
|
||||
"""
|
||||
|
||||
if choice == "Reset workspace":
|
||||
reset_camoufox()
|
||||
easygui.msgbox("Reset completed and bootstrap patches applied.", "Reset Complete")
|
||||
|
||||
elif choice == "Select patches":
|
||||
run_patches(reverse=False)
|
||||
easygui.msgbox("Patching completed.", "Patching Complete")
|
||||
def handle_choice(choice):
|
||||
match choice:
|
||||
case "Reset workspace":
|
||||
reset_camoufox()
|
||||
easygui.msgbox("Reset completed and bootstrap patches applied.", "Reset Complete")
|
||||
|
||||
elif choice == "Reverse patches":
|
||||
run_patches(reverse=True)
|
||||
easygui.msgbox("Unpatching completed.", "Unpatching Complete")
|
||||
case "Select patches":
|
||||
run_patches(reverse=False)
|
||||
easygui.msgbox("Patching completed.", "Patching Complete")
|
||||
|
||||
elif choice == "Find broken patches":
|
||||
reset_camoufox()
|
||||
case "Reverse patches":
|
||||
run_patches(reverse=True)
|
||||
easygui.msgbox("Unpatching completed.", "Unpatching Complete")
|
||||
|
||||
broken_patches = []
|
||||
for patch_file in list_files('../patches', suffix='*.patch'):
|
||||
cmd = rf'patch -p1 -i "{patch_file}" | tee /dev/stderr | sed -r --quiet \'s/^.*saving rejects to file (.*\.rej)$/\\1/p\''
|
||||
result = os.popen(cmd).read().strip()
|
||||
print(result)
|
||||
if result:
|
||||
broken_patches.append((patch_file, result))
|
||||
case "Find broken patches":
|
||||
reset_camoufox()
|
||||
|
||||
if not broken_patches:
|
||||
easygui.msgbox("All patches applied successfully", "Patching Result")
|
||||
else:
|
||||
message = "Some patches failed to apply:\n\n"
|
||||
for patch_file, rejects in broken_patches:
|
||||
message += f"Patch: {patch_file}\nRejects: {rejects}\n\n"
|
||||
easygui.textbox("Patching Result", "Failed Patches", message)
|
||||
broken_patches = []
|
||||
for patch_file in list_files('../patches', suffix='*.patch'):
|
||||
cmd = rf'patch -p1 -i "{patch_file}" | tee /dev/stderr | sed -r --quiet \'s/^.*saving rejects to file (.*\.rej)$/\\1/p\''
|
||||
result = os.popen(cmd).read().strip()
|
||||
print(result)
|
||||
if result:
|
||||
broken_patches.append((patch_file, result))
|
||||
|
||||
elif choice == "See current workspace":
|
||||
result = os.popen('git diff').read()
|
||||
easygui.textbox("Diff", "Diff", result)
|
||||
if not broken_patches:
|
||||
easygui.msgbox("All patches applied successfully", "Patching Result")
|
||||
else:
|
||||
message = "Some patches failed to apply:\n\n"
|
||||
for patch_file, rejects in broken_patches:
|
||||
message += f"Patch: {patch_file}\nRejects: {rejects}\n\n"
|
||||
easygui.textbox("Patching Result", "Failed Patches", message)
|
||||
|
||||
elif choice == "Write workspace to patch":
|
||||
# Open a file dialog to select a file to write the diff to
|
||||
file_path = easygui.filesavebox(
|
||||
"Select a file to write the diff to", "Write Diff", filetypes="*.patch"
|
||||
)
|
||||
if not file_path:
|
||||
exit()
|
||||
run(f'git diff > {file_path}')
|
||||
easygui.msgbox("Diff written to file", "Diff Written")
|
||||
case "See current workspace":
|
||||
result = os.popen('git diff').read()
|
||||
easygui.textbox("Diff", "Diff", result)
|
||||
|
||||
case "Write workspace to patch":
|
||||
# Open a file dialog to select a file to write the diff to
|
||||
file_path = easygui.filesavebox(
|
||||
"Select a file to write the diff to", "Write Diff", filetypes="*.patch"
|
||||
)
|
||||
if not file_path:
|
||||
exit()
|
||||
run(f'git diff > {file_path}')
|
||||
easygui.msgbox("Diff written to file", "Diff Written")
|
||||
|
||||
case _:
|
||||
print('No choice selected')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
into_camoufox_dir()
|
||||
|
||||
choice = easygui.choicebox("Select an option:", "Camoufox Dev Tools", choices)
|
||||
handle_choice(choice)
|
||||
|
||||
Reference in New Issue
Block a user