···11-#!/usr/bin/env python3
22-"""Remove dead code from lib.rs that has been moved to peek-core."""
33-44-import sys
55-66-LIB_RS = 'backend/tauri-mobile/src-tauri/src/lib.rs'
77-88-with open(LIB_RS, 'r') as f:
99- lines = f.readlines()
1010-1111-def find_line(text, start_from=0):
1212- """Find first line containing exact text."""
1313- for i in range(start_from, len(lines)):
1414- if text in lines[i]:
1515- return i
1616- return None
1717-1818-def find_fn_end(start_line):
1919- """Find the closing brace of a function starting at start_line."""
2020- depth = 0
2121- for i in range(start_line, len(lines)):
2222- depth += lines[i].count('{') - lines[i].count('}')
2323- if depth == 0 and '{' in ''.join(lines[start_line:i+1]):
2424- return i
2525- return None
2626-2727-removals = []
2828-2929-# 1. Remove ensure_database_initialized() — ~770 lines
3030-start = find_line('fn ensure_database_initialized() -> Result<(), String> {')
3131-if start is not None:
3232- end = find_fn_end(start)
3333- if end is not None:
3434- # Also remove the comment line before it
3535- comment_start = start
3636- while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'):
3737- comment_start -= 1
3838- # Include blank line after
3939- end_with_blank = end + 1
4040- while end_with_blank < len(lines) and lines[end_with_blank].strip() == '':
4141- end_with_blank += 1
4242- removals.append((comment_start, end_with_blank,
4343- '// ensure_database_initialized() moved to peek-core::schema\n\n'))
4444- print(f'ensure_database_initialized: lines {comment_start+1}-{end_with_blank}')
4545-4646-# 2. Remove parse_iso_datetime, unix_ms_to_iso, unix_ms_to_datetime
4747-for fn_name in ['parse_iso_datetime', 'unix_ms_to_iso', 'unix_ms_to_datetime']:
4848- start = find_line(f'fn {fn_name}(')
4949- if start is not None:
5050- end = find_fn_end(start)
5151- if end is not None:
5252- # Include comment before
5353- comment_start = start
5454- while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'):
5555- comment_start -= 1
5656- end_with_blank = end + 1
5757- while end_with_blank < len(lines) and lines[end_with_blank].strip() == '':
5858- end_with_blank += 1
5959- removals.append((comment_start, end_with_blank, ''))
6060- print(f'{fn_name}: lines {comment_start+1}-{end_with_blank}')
6161-6262-# 3. Remove check_response_version_headers (still used - skip if referenced elsewhere)
6363-# Actually this is still used in pull_from_server, keep it.
6464-6565-# 4. Remove get_items_to_push (standalone fn)
6666-start = find_line('fn get_items_to_push(conn: &Connection)')
6767-if start is not None:
6868- end = find_fn_end(start)
6969- if end is not None:
7070- comment_start = start
7171- while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'):
7272- comment_start -= 1
7373- end_with_blank = end + 1
7474- while end_with_blank < len(lines) and lines[end_with_blank].strip() == '':
7575- end_with_blank += 1
7676- removals.append((comment_start, end_with_blank, ''))
7777- print(f'get_items_to_push: lines {comment_start+1}-{end_with_blank}')
7878-7979-# 5. Remove get_item_tags (standalone fn, NOT the test helper)
8080-start = find_line('fn get_item_tags(conn: &Connection, item_id: &str) -> Result<Vec<String>, String>')
8181-if start is not None:
8282- end = find_fn_end(start)
8383- if end is not None:
8484- comment_start = start
8585- while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'):
8686- comment_start -= 1
8787- end_with_blank = end + 1
8888- while end_with_blank < len(lines) and lines[end_with_blank].strip() == '':
8989- end_with_blank += 1
9090- removals.append((comment_start, end_with_blank, ''))
9191- print(f'get_item_tags: lines {comment_start+1}-{end_with_blank}')
9292-9393-# 6. Remove merge_server_item
9494-start = find_line('fn merge_server_item(conn: &Connection, server_item: &ServerItem)')
9595-if start is not None:
9696- end = find_fn_end(start)
9797- if end is not None:
9898- comment_start = start
9999- while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'):
100100- comment_start -= 1
101101- end_with_blank = end + 1
102102- while end_with_blank < len(lines) and lines[end_with_blank].strip() == '':
103103- end_with_blank += 1
104104- removals.append((comment_start, end_with_blank, ''))
105105- print(f'merge_server_item: lines {comment_start+1}-{end_with_blank}')
106106-107107-# 7. Remove update_item_tags_from_server
108108-start = find_line('fn update_item_tags_from_server(conn: &Connection, item_id: &str, tag_names: &[String])')
109109-if start is not None:
110110- end = find_fn_end(start)
111111- if end is not None:
112112- comment_start = start
113113- while comment_start > 0 and lines[comment_start - 1].strip().startswith('//'):
114114- comment_start -= 1
115115- end_with_blank = end + 1
116116- while end_with_blank < len(lines) and lines[end_with_blank].strip() == '':
117117- end_with_blank += 1
118118- removals.append((comment_start, end_with_blank, ''))
119119- print(f'update_item_tags_from_server: lines {comment_start+1}-{end_with_blank}')
120120-121121-if not removals:
122122- print('No functions found to remove!')
123123- sys.exit(1)
124124-125125-# Sort removals in reverse order so line numbers stay valid
126126-removals.sort(key=lambda x: x[0], reverse=True)
127127-128128-for start, end, replacement in removals:
129129- lines[start:end] = [replacement] if replacement else []
130130-131131-with open(LIB_RS, 'w') as f:
132132- f.writelines(lines)
133133-134134-total_removed = sum(end - start for start, end, _ in removals)
135135-print(f'\nTotal: removed {total_removed} lines from lib.rs')