-
Notifications
You must be signed in to change notification settings - Fork 0
Hotfix/sumo #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hotfix/sumo #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/usr/bin/env python3 | ||
| """Fix XML files to have XML declaration at the beginning""" | ||
|
|
||
| import os | ||
| import re | ||
| from pathlib import Path | ||
|
Comment on lines
+1
to
+6
|
||
|
|
||
| def fix_xml_file(filepath): | ||
| """Fix a single XML file""" | ||
| with open(filepath, 'r', encoding='utf-8') as f: | ||
| content = f.read() | ||
|
|
||
| # Check if file starts with XML declaration | ||
| if content.strip().startswith('<?xml'): | ||
| print(f"β {filepath.name} - Already correct") | ||
| return False | ||
|
|
||
| # Find the XML declaration | ||
| xml_decl_pattern = r'<\?xml[^?]*\?>' | ||
| match = re.search(xml_decl_pattern, content) | ||
|
|
||
| if not match: | ||
| print(f"β {filepath.name} - No XML declaration found") | ||
| return False | ||
|
|
||
| # Extract XML declaration | ||
| xml_decl = match.group(0) | ||
|
|
||
| # Remove the XML declaration from its current position | ||
| content_without_decl = content.replace(xml_decl, '', 1) | ||
|
|
||
| # Remove leading whitespace/newlines but keep copyright comments | ||
| content_without_decl = content_without_decl.lstrip('\n') | ||
|
|
||
| # Put XML declaration at the beginning | ||
| new_content = xml_decl + '\n' + content_without_decl | ||
|
|
||
| # Write back | ||
| with open(filepath, 'w', encoding='utf-8') as f: | ||
| f.write(new_content) | ||
|
|
||
| print(f"β {filepath.name} - Fixed") | ||
| return True | ||
|
Comment on lines
+8
to
+43
|
||
|
|
||
| def main(): | ||
| # Path to Nga4ThuDuc directory | ||
| nga4_dir = Path('/home/thaianh/Study/GreenWave/src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc') | ||
|
||
|
|
||
| print("Fixing XML files in Nga4ThuDuc directory...\n") | ||
|
|
||
| fixed_count = 0 | ||
|
|
||
| # Fix all .xml and .sumocfg files | ||
| for pattern in ['*.xml', '*.sumocfg']: | ||
| for filepath in nga4_dir.glob(pattern): | ||
| if fix_xml_file(filepath): | ||
| fixed_count += 1 | ||
|
|
||
| print(f"\nTotal files fixed: {fixed_count}") | ||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
|
Comment on lines
+1
to
+62
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,67 @@ | ||||
| #!/usr/bin/env python3 | ||||
| """ | ||||
| Resolve Git merge conflicts in XML files | ||||
| Keeps the HEAD version (current branch) and removes conflict markers | ||||
| """ | ||||
|
|
||||
|
Comment on lines
+1
to
+6
|
||||
| import os | ||||
|
||||
| import os |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern doesn't handle all edge cases properly. The pattern requires a newline after >>>>>>> but the marker might appear at the end of the file without a trailing newline. Consider using:
conflict_pattern = r'<<<<<<< HEAD\n(.*?)\n=======\n(.*?)\n>>>>>>> [^\n]*\n?'Also, the second pass removals should use re.MULTILINE flag to properly handle line boundaries.
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded absolute path /home/thaianh/Study/GreenWave/src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc makes this script non-portable. Use a relative path or make the path configurable via command-line arguments. For example:
nga4_dir = Path(__file__).parent / 'src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc'or accept it as a command-line argument.
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This utility script should be placed in the scripts/ directory instead of the repository root to maintain better organization and consistency with other utility scripts like check_sumo.py and connect_sumo.py.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
|
||||
| <?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'os' is not used.