From 0e642000e0ac8044e3444a1466224f935ed926dd Mon Sep 17 00:00:00 2001 From: elkanamol Date: Thu, 5 Sep 2024 16:14:28 +0300 Subject: [PATCH] removing unusing cose, adding docstrings --- sierra_status/src/cli.py | 49 ++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/sierra_status/src/cli.py b/sierra_status/src/cli.py index 70b005b..60b59c2 100644 --- a/sierra_status/src/cli.py +++ b/sierra_status/src/cli.py @@ -9,42 +9,63 @@ DEFAULT_BAUDRATE = 115200 def setup_logging(verbose: bool) -> None: + """ + Sets up the logging configuration based on the provided verbosity level. + + Args: + verbose (bool): If True, sets the log level to DEBUG, otherwise sets it to INFO. + + Returns: + None + """ log_level = logging.DEBUG if verbose else logging.INFO logging.basicConfig(level=log_level) def validate_port(port: str) -> None: + """ + Validates that the specified USB port exists on the system. + + Args: + port (str): The USB port to validate. + + Raises: + ValueError: If the specified USB port does not exist. + """ if not os.path.exists(port): raise ValueError(f"The specified port '{port}' does not exist.") -# def validate_port(port: str) -> None: -# if sys.platform.startswith('win'): -# # For Windows, we can't easily validate COM ports -# # We could potentially use the winreg module to check available ports -# logging.warning("Windows does not have a built-in way to validate COM ports.") -# pass -# else: -# # For Unix-like systems, check if the device file exists -# if not os.path.exists(port): -# raise ValueError(f"The specified port '{port}' does not exist.") - def main() -> None: + """ + The main entry point for the Sierra Wireless EM9xxx/EM7xxx CLI tool. + + This function sets up the command-line argument parser, validates the specified + USB port, and starts the process to query the status of the Sierra Wireless + module. + + Args: + None + + Raises: + ValueError: If the specified USB port does not exist. + Exception: If any other error occurs during the execution of the tool. + """ sys.path.append(os.path.dirname(os.path.abspath(__file__))) parser = argparse.ArgumentParser( description="CLI tool for Sierra Wireless EM9xxx/EM7xxx modules to query status", formatter_class=argparse.RawTextHelpFormatter ) - + required = parser.add_argument_group('required arguments') required.add_argument("-p", "--port", help="USB port to use (e.g., 'COM1' for Windows or '/dev/ttyUSB2' for Linux)", required=True) - + optional = parser.add_argument_group('optional arguments') optional.add_argument("--version", help="Show version", action="version", version=f"%(prog)s {__version__}") optional.add_argument("-m", "--model", help="Model of the device to add to filename (e.g., EM9191 or EM7455)", default="") optional.add_argument("-v", "--verbose", help="Enable verbose output", action="store_true") optional.add_argument("-s", "--search", help="Search for network using AT!COPS=?", action="store_true") optional.add_argument("-b", "--baudrate", help=f"Baudrate to use for serial communication (default: {DEFAULT_BAUDRATE})", default=DEFAULT_BAUDRATE, type=int) - + args = parser.parse_args() setup_logging(args.verbose)