From ff78a756dad274a3d79953855c04ec4da0919205 Mon Sep 17 00:00:00 2001 From: Elkana Molson Date: Sun, 1 Sep 2024 16:40:14 +0300 Subject: [PATCH 01/15] Update the file to build for Linux --- .github/workflows/build_exe.yml | 40 ++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build_exe.yml b/.github/workflows/build_exe.yml index 20346d7..46eb4d9 100644 --- a/.github/workflows/build_exe.yml +++ b/.github/workflows/build_exe.yml @@ -1,43 +1,53 @@ -name: Generate Python Executable for Windows +name: Generate Python Executable for Linux on: - workflow_dispatch: # manually triggered + workflow_dispatch: inputs: tag: required: true type: string - description: the semver tag your release will have + description: The semver tag for your Linux release jobs: - create-executable-and-release: - runs-on: windows-latest + create-linux-executable-and-release: + runs-on: ubuntu-latest permissions: - contents: write #allows the job to create a release + contents: write + defaults: + run: + working-directory: . steps: - name: Checkout code uses: actions/checkout@v4 - - uses: ./.github/actions/Build_Executable - name: sierra-status # name of the step - name: Setup Python uses: actions/setup-python@v5 with: - python-version: 3.10 + python-version: "3.8.10" - name: Install requirements - # working-directory: # can remove this field if your working directory is root run: pip install -r requirements.txt - name: Install Pyinstaller run: pip install -U pyinstaller - name: Compile executable - # working-directory: # again, app directory here or skip if root - run: pyinstaller --onefile --name sierra-status --hidden-import=serial --hidden-import=argparse .\sierra_status\src\cli.py #or whatever your main file is named + run: | + export PYTHONPATH="$GITHUB_WORKSPACE:$PYTHONPATH" + pyinstaller --onefile --name sierra-status-linux --hidden-import=sierra_status.__version__ --hidden-import=serial --hidden-import=argparse --add-data "sierra_status:sierra_status" ./sierra_status/src/cli.py + + - name: Check working directory + run: | + pwd + ls -R - name: Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: - files: dist/sierra-status.exe - tag_name: ${{ inputs.tag }} + files: dist/sierra-status-linux + tag_name: ${{ inputs.tag }}-linux + + - name: Print directory structure + run: | + find . From 99ddd27f1f6af44533f923f0cfccb8aee04933a7 Mon Sep 17 00:00:00 2001 From: Elkana Molson Date: Sun, 1 Sep 2024 16:42:34 +0300 Subject: [PATCH 02/15] update python version --- .github/workflows/build_exe.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_exe.yml b/.github/workflows/build_exe.yml index 46eb4d9..691878d 100644 --- a/.github/workflows/build_exe.yml +++ b/.github/workflows/build_exe.yml @@ -24,7 +24,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: "3.8.10" + python-version: "3.X" - name: Install requirements run: pip install -r requirements.txt From 4831c482c38ea59778eddada632a9ae071e2b559 Mon Sep 17 00:00:00 2001 From: Elkana Molson Date: Sun, 1 Sep 2024 16:44:25 +0300 Subject: [PATCH 03/15] update Python version --- .github/workflows/build_exe.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_exe.yml b/.github/workflows/build_exe.yml index 691878d..063414b 100644 --- a/.github/workflows/build_exe.yml +++ b/.github/workflows/build_exe.yml @@ -24,7 +24,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: "3.X" + python-version: "3.8.11" - name: Install requirements run: pip install -r requirements.txt From ae23b34764e84d61074ba9142979eec1deac3d06 Mon Sep 17 00:00:00 2001 From: Elkana Molson Date: Sun, 1 Sep 2024 16:48:23 +0300 Subject: [PATCH 04/15] Update build_exe.yml --- .github/workflows/build_exe.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_exe.yml b/.github/workflows/build_exe.yml index 063414b..b116ae6 100644 --- a/.github/workflows/build_exe.yml +++ b/.github/workflows/build_exe.yml @@ -24,7 +24,8 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: "3.8.11" + python-version: '3.x' + architecture: 'x64' - name: Install requirements run: pip install -r requirements.txt From 99610b4c6c5f225645af81909b558b27d9979ec2 Mon Sep 17 00:00:00 2001 From: Elkana Molson <57934787+elkanamol@users.noreply.github.com> Date: Sun, 1 Sep 2024 16:51:27 +0300 Subject: [PATCH 05/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b052621..0df7cf7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # sierra_status - +[![Generate Python Executable for Windows](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml) ## Overview em-mc_status_script is a Python-based CLI tool designed to retrieve and analyze the status of Sierra Wireless EM9xxx,EM7xxx and WP76xx modules. This script provides a quick and efficient way to gather essential information from these modules using AT commands. From 25a9d27914e800134b6f4fda6024f6e278bc3697 Mon Sep 17 00:00:00 2001 From: Elkana Molson Date: Sun, 1 Sep 2024 16:52:29 +0300 Subject: [PATCH 06/15] remove special Linux tag --- .github/workflows/build_exe.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_exe.yml b/.github/workflows/build_exe.yml index b116ae6..0968a62 100644 --- a/.github/workflows/build_exe.yml +++ b/.github/workflows/build_exe.yml @@ -47,7 +47,7 @@ jobs: uses: softprops/action-gh-release@v2 with: files: dist/sierra-status-linux - tag_name: ${{ inputs.tag }}-linux + tag_name: ${{ inputs.tag }} - name: Print directory structure run: | From 86e5af4a85e22d22a83726559e9877de3e64dcb4 Mon Sep 17 00:00:00 2001 From: Elkana Molson <57934787+elkanamol@users.noreply.github.com> Date: Sun, 1 Sep 2024 16:57:24 +0300 Subject: [PATCH 07/15] Update README.md add new badges for Linux and Windows build --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0df7cf7..c69c7d3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # sierra_status -[![Generate Python Executable for Windows](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml) +[![Generate Python Executable for Windows](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml) [![Generate Python Executable for Linux](https://github.com/elkanamol/sierra_status/actions/workflows/build_exe.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/build_exe.yml) ## Overview em-mc_status_script is a Python-based CLI tool designed to retrieve and analyze the status of Sierra Wireless EM9xxx,EM7xxx and WP76xx modules. This script provides a quick and efficient way to gather essential information from these modules using AT commands. From e130de98d4fa956ce8de8e864637e4d174c9f63a Mon Sep 17 00:00:00 2001 From: Elkana Molson Date: Sun, 1 Sep 2024 17:10:26 +0300 Subject: [PATCH 08/15] Adding test.yml to run the test --- .github/workflows/test.yml | 57 ++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 59 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..746532d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,57 @@ +name: Run Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.8.x' + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pytest pytest-cov flake8 + + - name: Run linting + run: flake8 . + + - name: Run tests with pytest and coverage + id: run-tests + run: | + pytest_output=$(pytest --cov=sierra_status --cov-report=xml) + echo "::set-output name=pytest_output::$pytest_output" + + + + - name: Upload coverage report + uses: codecov/codecov-action@v3 + with: + file: ./coverage.xml + flags: unittests + + - name: Print test results + if: always() + run: | + echo "Test Results:" + echo "${{ steps.run-tests.outputs.pytest_output }}" diff --git a/README.md b/README.md index 0df7cf7..58aca38 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # sierra_status + [![Generate Python Executable for Windows](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml) + ## Overview em-mc_status_script is a Python-based CLI tool designed to retrieve and analyze the status of Sierra Wireless EM9xxx,EM7xxx and WP76xx modules. This script provides a quick and efficient way to gather essential information from these modules using AT commands. From d80e9fb6fcdeb6de3f820fcf2a27400d99b13e6a Mon Sep 17 00:00:00 2001 From: Elkana Molson Date: Sun, 1 Sep 2024 17:16:42 +0300 Subject: [PATCH 09/15] Remove flake8 --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 746532d..5a9e731 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,8 +33,8 @@ jobs: pip install -r requirements.txt pip install pytest pytest-cov flake8 - - name: Run linting - run: flake8 . + # - name: Run linting + # run: flake8 . - name: Run tests with pytest and coverage id: run-tests From ef76ab107e21ee55dbdd62af945aad2870f71503 Mon Sep 17 00:00:00 2001 From: Elkana Molson Date: Sun, 1 Sep 2024 17:23:46 +0300 Subject: [PATCH 10/15] changing to unittest --- .github/workflows/test.yml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5a9e731..9791d70 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,27 +31,19 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install pytest pytest-cov flake8 + pip install flake8 # - name: Run linting # run: flake8 . - - name: Run tests with pytest and coverage + - name: Run tests with unittest id: run-tests run: | - pytest_output=$(pytest --cov=sierra_status --cov-report=xml) - echo "::set-output name=pytest_output::$pytest_output" - - - - - name: Upload coverage report - uses: codecov/codecov-action@v3 - with: - file: ./coverage.xml - flags: unittests + test_output=$(python -m unittest discover tests) + echo "::set-output name=test_output::$test_output" - name: Print test results if: always() run: | echo "Test Results:" - echo "${{ steps.run-tests.outputs.pytest_output }}" + echo "${{ steps.run-tests.outputs.test_output }}" \ No newline at end of file From b58dc3e53f6a7b347711f2c81ff62a1f094715b6 Mon Sep 17 00:00:00 2001 From: Elkana Molson <57934787+elkanamol@users.noreply.github.com> Date: Sun, 1 Sep 2024 17:29:12 +0300 Subject: [PATCH 11/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 072708d..7da6d58 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # sierra_status -[![Generate Python Executable for Windows](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml) [![Generate Python Executable for Linux](https://github.com/elkanamol/sierra_status/actions/workflows/build_exe.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/build_exe.yml) +[![Generate Python Executable for Windows](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/Build_Executable.yml) [![Generate Python Executable for Linux](https://github.com/elkanamol/sierra_status/actions/workflows/build_exe.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/build_exe.yml)[![Run Tests](https://github.com/elkanamol/sierra_status/actions/workflows/test.yml/badge.svg)](https://github.com/elkanamol/sierra_status/actions/workflows/test.yml) ## Overview From b2b6539a3f86f0dfc12f0003fdd8f1ab5b3d24a0 Mon Sep 17 00:00:00 2001 From: Elkana Molson Date: Sun, 1 Sep 2024 17:35:06 +0300 Subject: [PATCH 12/15] fix annotation issue of deprecated variables --- .github/workflows/test.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9791d70..3a4b791 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,13 +20,12 @@ jobs: python-version: '3.8.x' - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - - name: Install dependencies run: | python -m pip install --upgrade pip @@ -40,10 +39,12 @@ jobs: id: run-tests run: | test_output=$(python -m unittest discover tests) - echo "::set-output name=test_output::$test_output" + echo "test_output<> $GITHUB_OUTPUT + echo "$test_output" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT - name: Print test results if: always() run: | echo "Test Results:" - echo "${{ steps.run-tests.outputs.test_output }}" \ No newline at end of file + echo "${{ steps.run-tests.outputs.test_output }}" echo "${{ steps.run-tests.outputs.test_output }}" \ No newline at end of file From bac5ea3eec3cbad25ac5912923d39130d085fd24 Mon Sep 17 00:00:00 2001 From: elkanamol Date: Thu, 5 Sep 2024 16:06:46 +0300 Subject: [PATCH 13/15] add port validation and error handling - Implement cross-platform port validation using os.path.exists() - Add try-except block to handle exceptions in main function - Improve error reporting for invalid ports - Enhance user feedback with specific error messages --- sierra_status/src/cli.py | 44 ++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/sierra_status/src/cli.py b/sierra_status/src/cli.py index 530bb25..70b005b 100644 --- a/sierra_status/src/cli.py +++ b/sierra_status/src/cli.py @@ -1,8 +1,31 @@ -from sierra_status.__version__ import __version__ import argparse import logging +import sys +import os + +from sierra_status.__version__ import __version__ from sierra_status.src import usb_handle -import sys, os + +DEFAULT_BAUDRATE = 115200 + +def setup_logging(verbose: bool) -> None: + log_level = logging.DEBUG if verbose else logging.INFO + logging.basicConfig(level=log_level) + +def validate_port(port: str) -> None: + 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: sys.path.append(os.path.dirname(os.path.abspath(__file__))) @@ -20,13 +43,18 @@ def main() -> None: 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="Baudrate to use for serial communication (default: 115200)", default=115200, type=int) + 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() - log_level = logging.DEBUG if args.verbose else logging.INFO - logging.basicConfig(level=log_level) - usb_handle.start_process(args.port, args.model.lower(), log_level, args.search, args.baudrate) + setup_logging(args.verbose) + + try: + validate_port(args.port) + usb_handle.start_process(args.port, args.model.lower(), logging.getLogger().level, args.search, args.baudrate) + except Exception as e: + logging.error(f"An error occurred: {str(e)}") + sys.exit(1) if __name__ == "__main__": - main() - \ No newline at end of file + main() From fcdbcfa8dd9226243e16cd943f4742b20ed71be1 Mon Sep 17 00:00:00 2001 From: elkanamol Date: Thu, 5 Sep 2024 16:14:28 +0300 Subject: [PATCH 14/15] 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) From 6e429f942327e1ed5bb382b7c89c8857075de932 Mon Sep 17 00:00:00 2001 From: elkanamol Date: Sun, 8 Sep 2024 10:45:20 +0300 Subject: [PATCH 15/15] update the package version --- sierra_status/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sierra_status/__version__.py b/sierra_status/__version__.py index 48fef32..51e0a06 100644 --- a/sierra_status/__version__.py +++ b/sierra_status/__version__.py @@ -1 +1 @@ -__version__ = "0.1.2" \ No newline at end of file +__version__ = "0.1.4" \ No newline at end of file