11#!/usr/bin/env python3
22"""
3- Script to run an opmode class derived from the Opmode base class.
3+ Script to run an opmode class derived from the OpMode base class.
44
55Usage:
66 python run_opmode.py <opmode_file.py>
77
8- The opmode file should contain a class that inherits from Opmode .
8+ The opmode file should contain a class that inherits from OpMode .
99"""
1010
1111import sys
1818# Add the current directory to Python path to import local modules
1919sys .path .insert (0 , str (Path (__file__ ).parent ))
2020
21- from opmode import Opmode
21+ from opmode import OpMode
2222from robot import Robot
2323
2424
2525def find_opmode_class (module ):
2626 """
27- Find the first class in the module that inherits from Opmode .
27+ Find the first class in the module that inherits from OpMode .
2828
2929 Args:
3030 module: The imported Python module
3131
3232 Returns:
33- The Opmode -derived class, or None if not found
33+ The OpMode -derived class, or None if not found
3434 """
3535 for name , obj in inspect .getmembers (module , inspect .isclass ):
36- if obj != Opmode and issubclass (obj , Opmode ):
36+ if obj != OpMode and issubclass (obj , OpMode ):
3737 return obj
3838 return None
3939
@@ -46,17 +46,17 @@ def load_opmode_from_file(file_path):
4646 file_path: Path to the Python file containing the opmode class
4747
4848 Returns:
49- The Opmode -derived class
49+ The OpMode -derived class
5050
5151 Raises:
5252 FileNotFoundError: If the file doesn't exist
5353 ImportError: If the file can't be imported
54- ValueError: If no Opmode -derived class is found
54+ ValueError: If no OpMode -derived class is found
5555 """
5656 file_path = Path (file_path )
5757
5858 if not file_path .exists ():
59- raise FileNotFoundError (f"Opmode file not found: { file_path } " )
59+ raise FileNotFoundError (f"OpMode file not found: { file_path } " )
6060
6161 if not file_path .suffix == '.py' :
6262 raise ValueError (f"File must be a Python file (.py): { file_path } " )
@@ -69,10 +69,10 @@ def load_opmode_from_file(file_path):
6969 module = importlib .util .module_from_spec (spec )
7070 spec .loader .exec_module (module )
7171
72- # Find the Opmode -derived class
72+ # Find the OpMode -derived class
7373 opmode_class = find_opmode_class (module )
7474 if opmode_class is None :
75- raise ValueError (f"No class derived from Opmode found in { file_path } " )
75+ raise ValueError (f"No class derived from OpMode found in { file_path } " )
7676
7777 return opmode_class
7878
@@ -146,7 +146,7 @@ def run_opmode(opmode_file, duration=None, loop_frequency=50):
146146 total_time = time .time () - start_time
147147 actual_frequency = loop_count / total_time if total_time > 0 else 0
148148
149- print (f"\n Opmode completed:" )
149+ print (f"\n OpMode completed:" )
150150 print (f" Total runtime: { total_time :.2f} seconds" )
151151 print (f" Total loops: { loop_count } " )
152152 print (f" Average frequency: { actual_frequency :.1f} Hz" )
@@ -159,7 +159,7 @@ def run_opmode(opmode_file, duration=None, loop_frequency=50):
159159def main ():
160160 """Main entry point."""
161161 parser = argparse .ArgumentParser (
162- description = "Run an opmode class derived from Opmode " ,
162+ description = "Run an opmode class derived from OpMode " ,
163163 formatter_class = argparse .RawDescriptionHelpFormatter ,
164164 epilog = """
165165Examples:
0 commit comments