experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: remove dead code removal script

-135
-135
scripts/remove-dead-code.py
··· 1 - #!/usr/bin/env python3 2 - """Remove dead code from lib.rs that has been moved to peek-core.""" 3 - 4 - import sys 5 - 6 - LIB_RS = 'backend/tauri-mobile/src-tauri/src/lib.rs' 7 - 8 - with open(LIB_RS, 'r') as f: 9 - lines = f.readlines() 10 - 11 - def find_line(text, start_from=0): 12 - """Find first line containing exact text.""" 13 - for i in range(start_from, len(lines)): 14 - if text in lines[i]: 15 - return i 16 - return None 17 - 18 - def find_fn_end(start_line): 19 - """Find the closing brace of a function starting at start_line.""" 20 - depth = 0 21 - for i in range(start_line, len(lines)): 22 - depth += lines[i].count('{') - lines[i].count('}') 23 - if depth == 0 and '{' in ''.join(lines[start_line:i+1]): 24 - return i 25 - return None 26 - 27 - removals = [] 28 - 29 - # 1. Remove ensure_database_initialized() — ~770 lines 30 - start = find_line('fn ensure_database_initialized() -> Result<(), String> {') 31 - if start is not None: 32 - end = find_fn_end(start) 33 - if end is not None: 34 - # Also remove the comment line before it 35 - comment_start = start 36 - while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'): 37 - comment_start -= 1 38 - # Include blank line after 39 - end_with_blank = end + 1 40 - while end_with_blank < len(lines) and lines[end_with_blank].strip() == '': 41 - end_with_blank += 1 42 - removals.append((comment_start, end_with_blank, 43 - '// ensure_database_initialized() moved to peek-core::schema\n\n')) 44 - print(f'ensure_database_initialized: lines {comment_start+1}-{end_with_blank}') 45 - 46 - # 2. Remove parse_iso_datetime, unix_ms_to_iso, unix_ms_to_datetime 47 - for fn_name in ['parse_iso_datetime', 'unix_ms_to_iso', 'unix_ms_to_datetime']: 48 - start = find_line(f'fn {fn_name}(') 49 - if start is not None: 50 - end = find_fn_end(start) 51 - if end is not None: 52 - # Include comment before 53 - comment_start = start 54 - while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'): 55 - comment_start -= 1 56 - end_with_blank = end + 1 57 - while end_with_blank < len(lines) and lines[end_with_blank].strip() == '': 58 - end_with_blank += 1 59 - removals.append((comment_start, end_with_blank, '')) 60 - print(f'{fn_name}: lines {comment_start+1}-{end_with_blank}') 61 - 62 - # 3. Remove check_response_version_headers (still used - skip if referenced elsewhere) 63 - # Actually this is still used in pull_from_server, keep it. 64 - 65 - # 4. Remove get_items_to_push (standalone fn) 66 - start = find_line('fn get_items_to_push(conn: &Connection)') 67 - if start is not None: 68 - end = find_fn_end(start) 69 - if end is not None: 70 - comment_start = start 71 - while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'): 72 - comment_start -= 1 73 - end_with_blank = end + 1 74 - while end_with_blank < len(lines) and lines[end_with_blank].strip() == '': 75 - end_with_blank += 1 76 - removals.append((comment_start, end_with_blank, '')) 77 - print(f'get_items_to_push: lines {comment_start+1}-{end_with_blank}') 78 - 79 - # 5. Remove get_item_tags (standalone fn, NOT the test helper) 80 - start = find_line('fn get_item_tags(conn: &Connection, item_id: &str) -> Result<Vec<String>, String>') 81 - if start is not None: 82 - end = find_fn_end(start) 83 - if end is not None: 84 - comment_start = start 85 - while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'): 86 - comment_start -= 1 87 - end_with_blank = end + 1 88 - while end_with_blank < len(lines) and lines[end_with_blank].strip() == '': 89 - end_with_blank += 1 90 - removals.append((comment_start, end_with_blank, '')) 91 - print(f'get_item_tags: lines {comment_start+1}-{end_with_blank}') 92 - 93 - # 6. Remove merge_server_item 94 - start = find_line('fn merge_server_item(conn: &Connection, server_item: &ServerItem)') 95 - if start is not None: 96 - end = find_fn_end(start) 97 - if end is not None: 98 - comment_start = start 99 - while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'): 100 - comment_start -= 1 101 - end_with_blank = end + 1 102 - while end_with_blank < len(lines) and lines[end_with_blank].strip() == '': 103 - end_with_blank += 1 104 - removals.append((comment_start, end_with_blank, '')) 105 - print(f'merge_server_item: lines {comment_start+1}-{end_with_blank}') 106 - 107 - # 7. Remove update_item_tags_from_server 108 - start = find_line('fn update_item_tags_from_server(conn: &Connection, item_id: &str, tag_names: &[String])') 109 - if start is not None: 110 - end = find_fn_end(start) 111 - if end is not None: 112 - comment_start = start 113 - while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'): 114 - comment_start -= 1 115 - end_with_blank = end + 1 116 - while end_with_blank < len(lines) and lines[end_with_blank].strip() == '': 117 - end_with_blank += 1 118 - removals.append((comment_start, end_with_blank, '')) 119 - print(f'update_item_tags_from_server: lines {comment_start+1}-{end_with_blank}') 120 - 121 - if not removals: 122 - print('No functions found to remove!') 123 - sys.exit(1) 124 - 125 - # Sort removals in reverse order so line numbers stay valid 126 - removals.sort(key=lambda x: x[0], reverse=True) 127 - 128 - for start, end, replacement in removals: 129 - lines[start:end] = [replacement] if replacement else [] 130 - 131 - with open(LIB_RS, 'w') as f: 132 - f.writelines(lines) 133 - 134 - total_removed = sum(end - start for start, end, _ in removals) 135 - print(f'\nTotal: removed {total_removed} lines from lib.rs')