import re
import sys
from pathlib import Path
def fix_imports(content):
content = re.sub(
r'use sombra::\{([^}]*?GraphDB[^}]*?PropertyValue[^}]*?)\};',
r'use sombra::{GraphDB, PropertyValue, Node, Edge};',
content
)
content = content.replace('use std::collections::HashMap', 'use std::collections::BTreeMap')
content = content.replace('HashMap::', 'BTreeMap::')
return content
def fix_create_node_simple(content):
pattern = r'(\w+)\.create_node\(vec!\[(.*?)\], (\w+)\)'
def replace(m):
tx, labels, props = m.groups()
label_match = re.search(r'"([^"]+)"', labels)
if label_match:
label = label_match.group(1)
return f'''{{
let mut node = Node::new(0);
node.labels.push("{label}".to_string());
node.properties = {props};
{tx}.add_node(node)
}}'''
return m.group(0)
content = re.sub(pattern, replace, content)
return content
def fix_node_option_checks(content):
content = re.sub(r'(\w+)\.is_some\(\)', r'\1.is_ok()', content)
content = re.sub(r'(\w+)\.is_none\(\)', r'\1.is_err()', content)
return content
def process_file(filepath):
print(f"Processing {filepath}")
with open(filepath, 'r') as f:
content = f.read()
original = content
content = fix_imports(content)
content = fix_node_option_checks(content)
if content != original:
with open(filepath, 'w') as f:
f.write(content)
print(f" Modified {filepath}")
return True
return False
def main():
test_dir = Path('tests')
example_dir = Path('examples')
count = 0
for pattern in ['*.rs']:
for directory in [test_dir, example_dir]:
if directory.exists():
for filepath in directory.glob(pattern):
if process_file(filepath):
count += 1
print(f"\nModified {count} files")
if __name__ == '__main__':
main()