From e262c6dff8da4093aa66f7cfa4bca7235ca2f3fe Mon Sep 17 00:00:00 2001 From: madeofstown Date: Sun, 9 Mar 2025 21:20:55 -0700 Subject: [PATCH] `mvrun.py` changes --- README.md | 20 ++++++++++++------ meshview/templates/base.html | 2 +- mvrun.py | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 mvrun.py diff --git a/README.md b/README.md index c47b897..33e9624 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Copy `sample.config.ini` to `config.ini`: ``` bash cp sample.config.ini config.ini ``` - Edit `config.ini` and change the MQTT server, and Web server settings as necsessary. + Edit `config.ini` and change the MQTT server, and Web server settings. ```bash nano config.ini ``` @@ -71,12 +71,18 @@ Start the web server. ``` bash ./env/bin/python main.py ``` +> [!INFO] +> You can specify the path to your `config.ini` file with the run command argument `--config` +> ``` bash +>./env/bin/python startdb.py --config /path/to/config.ini +>./env/bin/python main.py --config /path/to/config.ini +>``` +## Running Meshview with `mvrun.py` +- `mvrun.py` starts `startdb.py` and `main.py` in their own subprocess threads and combines their terminal output. +- `mvrun.py` accepts the `--config` run command. - -Now you can hit http://localhost:8081/ ***(if you did not change the web server port )*** - -You can specify the path to your `config.ini` file with the run command argument `--config` ``` bash -./env/bin/python startdb.py --config /path/to/config.ini -./env/bin/python main.py --config /path/to/config.ini +./env/bin/python mvrun.py ``` + +Now you can hit http://localhost:8081/ ***(if you did not change the web server port )*** \ No newline at end of file diff --git a/meshview/templates/base.html b/meshview/templates/base.html index e1eb645..27e8b8a 100644 --- a/meshview/templates/base.html +++ b/meshview/templates/base.html @@ -1,7 +1,7 @@ - MeshView - Bay Area Mesh - http://meshview.bayme.sh {% if node and node.short_name %}-- {{node.short_name}}{% endif %} + Meshview - {{ site_config["site"]["title"] }} {% if node and node.short_name %}-- {{node.short_name}}{% endif %} diff --git a/mvrun.py b/mvrun.py new file mode 100644 index 0000000..f1e4f09 --- /dev/null +++ b/mvrun.py @@ -0,0 +1,41 @@ +import argparse +import threading +import subprocess + +# Run python in subprocess +def run_script(script_name, *args): + try: + # Path to the Python interpreter inside the virtual environment + python_executable = './env/bin/python' + + # Combine the script name and arguments + command = [python_executable, script_name] + list(args) + + # Run the subprocess and report errors + subprocess.run(command, check=True) + except Exception as e: + print(f"Error running {script_name}: {e}") + +# Parse runtime argument (--config) and start subprocess threads +def main(): + parser = argparse.ArgumentParser(description="Helper script to run the datbase and web frontend in separate threads.") + + # Add --config runtime argument + parser.add_argument('--config', help="Path to the configuration file.", default='config.ini') + args = parser.parse_args() + + # Database Thread + dbthrd = threading.Thread(target=run_script, args=('startdb.py', '--config', args.config)) + + # Web server thread + webthrd = threading.Thread(target=run_script, args=('main.py', '--config', args.config)) + + # Start Meshview subprocess threads + dbthrd.start() + webthrd.start() + + dbthrd.join() + webthrd.join() + +if __name__ == '__main__': + main() \ No newline at end of file