1+ import os
2+ import subprocess
3+
4+ def git_mv (old_path , new_path ):
5+ if os .path .exists (old_path ):
6+ # Create parent directory if it doesn't exist (for moving files)
7+ os .makedirs (os .path .dirname (new_path ), exist_ok = True )
8+ print (f"Renaming: { old_path } -> { new_path } " )
9+ subprocess .run (["git" , "mv" , old_path , new_path ], check = True )
10+
11+ def main ():
12+ # 1. Rename Directories
13+ # We walk bottom-up to ensure we don't rename a parent before its child is processed
14+ for root , dirs , files in os .walk ("." , topdown = False ):
15+ for name in dirs :
16+ if name == "Backends" :
17+ old_dir = os .path .join (root , name )
18+ new_dir = os .path .join (root , "Instrument_Control" )
19+ git_mv (old_dir , new_dir )
20+
21+ # 2. Rename Files
22+ # We walk again to find files in the new directory structure
23+ for root , dirs , files in os .walk ("." ):
24+ for name in files :
25+ if "_Backend" in name or "_Backened" in name :
26+ # Replace variants (including the typo 'Backened')
27+ new_name = name .replace ("_Backened" , "_Instrument_Control" )
28+ new_name = new_name .replace ("_Backend" , "_Instrument_Control" )
29+
30+ old_file = os .path .join (root , name )
31+ new_file = os .path .join (root , new_name )
32+
33+ if old_file != new_file :
34+ git_mv (old_file , new_file )
35+
36+ if __name__ == "__main__" :
37+ main ()
0 commit comments