Files
redmine/fix_tui_registration.py
Jason Thistlethwaite 9ee9eb3ec6 Organized
2026-10-17 20:50:35 -04:00

46 lines
1.3 KiB
Python

#!/usr/bin/env python3
import re
with open("redmine_tickets.py") as f:
txt = f.read()
# Clean any previous broken insertions around the area
txt = re.sub(
r'(\s*)\s*if add_tui_parser is not None:\s*add_tui_parser\(subparsers\)\s*\n\s*\)',
r'\1)',
txt
)
marker = ' help="Disable fzf right-hand preview pane.",\n )\n\n ocr_parser = subparsers.add_parser('
insert = ''' help="Disable fzf right-hand preview pane.",
)
if add_tui_parser is not None:
add_tui_parser(subparsers)
ocr_parser = subparsers.add_parser('''
if marker in txt:
txt = txt.replace(marker, insert, 1)
print("Inserted cleanly via marker")
else:
# Find by context and insert before ocr
ocr_pos = txt.find('ocr_parser = subparsers.add_parser(\n "ocr-rename"')
no_prev_pos = txt.find('--no-preview', 0)
if ocr_pos > 0 and no_prev_pos > 0 and ocr_pos > no_prev_pos:
# insert just before ocr
insert_block = '''
if add_tui_parser is not None:
add_tui_parser(subparsers)
'''
txt = txt[:ocr_pos] + insert_block + txt[ocr_pos:]
print("Inserted before ocr via fallback")
else:
print("Could not find good spot")
with open("redmine_tickets.py", "w") as f:
f.write(txt)
print("Done fixing registration")