-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix paho-mqtt dependency, rename config files to be app specific, ren…
…ame app and service to use hyphens
- Loading branch information
1 parent
f2d7ea0
commit b09a0f9
Showing
13 changed files
with
122 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
209 changes: 104 additions & 105 deletions
209
scripts/sentinel_mrhat_cam_main.py → bin/sentinel_mrhat_cam_main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,104 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import shutil | ||
from os import makedirs | ||
from os.path import dirname, exists, isdir, join | ||
from pathlib import Path | ||
|
||
from sentinel_mrhat_cam.app import App | ||
from sentinel_mrhat_cam.logger import Logger | ||
from sentinel_mrhat_cam.static_config import LOG_CONFIG_PATH, CONFIG_PATH, CONFIG_DIR | ||
import logging | ||
import sys | ||
|
||
|
||
def main(): | ||
""" | ||
Main entry point for the application. | ||
This function initializes the logger, creates an instance of the App class, | ||
and runs the application based on the configured mode. | ||
The application can run in three modes: | ||
1. "always-on": Continuously takes pictures and sends them. | ||
2. "periodic": Sends images periodically based on the configured schedule. | ||
3. "single-shot": Takes one picture, sends it, and then exits the script. | ||
The function handles the initialization of logging, creates the App instance | ||
with the provided configuration, and manages the main execution loop based | ||
on the selected mode. | ||
In case of a SystemExit exception, it logs the exit reason, disconnects | ||
from MQTT, and exits the application with the provided exit code. | ||
Raises | ||
------ | ||
SystemExit | ||
If the application needs to exit due to an error or completion of its task. | ||
Notes | ||
----- | ||
This function is the entry point of the application when run as a script. | ||
It sets up all necessary components and manages the main execution flow. | ||
""" | ||
|
||
# Setting up the configuration directory and copying the default configuration files if necessary | ||
_set_up_configuration() | ||
|
||
# Configuring and starting the logging | ||
logger = Logger(LOG_CONFIG_PATH) | ||
logger.start_logging() | ||
|
||
# Instantiating the Camera and MQTT objects with the provided configuration file | ||
app = App(CONFIG_PATH, logger) | ||
app.start() | ||
|
||
try: | ||
# The app is taking pictures nonstop | ||
if app.config.data['mode'] == "always-on": | ||
app.run_always() | ||
# The app is sending the images periodically | ||
elif app.config.data['mode'] == "periodic": | ||
app.run_periodically() | ||
# The app takes one picture then exit | ||
elif app.config.data['mode'] == "single-shot": | ||
app.run() | ||
|
||
except SystemExit as e: | ||
logging.info(f"Exit code in main: {e.code}\n Exiting the application because: {e}") | ||
sys.exit(e.code) | ||
finally: | ||
app.mqtt.disconnect() | ||
logger.disconnect_mqtt() | ||
|
||
|
||
def _set_up_configuration(): | ||
""" | ||
Set up the configuration directory and copy the default configuration files if necessary. | ||
This function creates the configuration directory if it does not exist and copies the default | ||
configuration files to the configuration directory if they do not exist. Will not overwrite existing files. | ||
Notes | ||
----- | ||
This function is called before the main function to ensure that the configuration files are | ||
available before the application starts. | ||
""" | ||
|
||
# Setting the default configuration path | ||
default_config_dir = str(Path(dirname(__file__)).parent.absolute().joinpath('config')) | ||
|
||
# Ensuring configuration directory exists | ||
if not isdir(CONFIG_DIR): | ||
makedirs(CONFIG_DIR, exist_ok=True) | ||
|
||
# Copying the default configuration files to the config directory, if they do not exist | ||
if not exists(LOG_CONFIG_PATH): | ||
default_log_config = join(default_config_dir, 'log_config.yaml') | ||
shutil.copy(default_log_config, LOG_CONFIG_PATH) | ||
|
||
if not exists(CONFIG_PATH): | ||
default_config = join(default_config_dir, 'config.json') | ||
shutil.copy(default_config, CONFIG_PATH) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
#!/usr/bin/env python3 | ||
|
||
import logging | ||
import shutil | ||
import sys | ||
from os import makedirs | ||
from os.path import dirname, exists, isdir, join, basename | ||
from pathlib import Path | ||
|
||
from sentinel_mrhat_cam.app import App | ||
from sentinel_mrhat_cam.logger import Logger | ||
from sentinel_mrhat_cam.static_config import LOG_CONFIG_PATH, CONFIG_PATH, CONFIG_DIR | ||
|
||
|
||
def main(): | ||
""" | ||
Main entry point for the application. | ||
This function initializes the logger, creates an instance of the App class, | ||
and runs the application based on the configured mode. | ||
The application can run in three modes: | ||
1. "always-on": Continuously takes pictures and sends them. | ||
2. "periodic": Sends images periodically based on the configured schedule. | ||
3. "single-shot": Takes one picture, sends it, and then exits the script. | ||
The function handles the initialization of logging, creates the App instance | ||
with the provided configuration, and manages the main execution loop based | ||
on the selected mode. | ||
In case of a SystemExit exception, it logs the exit reason, disconnects | ||
from MQTT, and exits the application with the provided exit code. | ||
Raises | ||
------ | ||
SystemExit | ||
If the application needs to exit due to an error or completion of its task. | ||
Notes | ||
----- | ||
This function is the entry point of the application when run as a script. | ||
It sets up all necessary components and manages the main execution flow. | ||
""" | ||
|
||
# Setting up the configuration directory and copying the default configuration files if necessary | ||
_set_up_configuration() | ||
|
||
# Configuring and starting the logging | ||
logger = Logger(LOG_CONFIG_PATH) | ||
logger.start_logging() | ||
|
||
# Instantiating the Camera and MQTT objects with the provided configuration file | ||
app = App(CONFIG_PATH, logger) | ||
app.start() | ||
|
||
try: | ||
# The app is taking pictures nonstop | ||
if app.config.data['mode'] == "always-on": | ||
app.run_always() | ||
# The app is sending the images periodically | ||
elif app.config.data['mode'] == "periodic": | ||
app.run_periodically() | ||
# The app takes one picture then exit | ||
elif app.config.data['mode'] == "single-shot": | ||
app.run() | ||
|
||
except SystemExit as e: | ||
logging.info(f"Exit code in main: {e.code}\n Exiting the application because: {e}") | ||
sys.exit(e.code) | ||
finally: | ||
app.mqtt.disconnect() | ||
logger.disconnect_mqtt() | ||
|
||
|
||
def _set_up_configuration(): | ||
""" | ||
Set up the configuration directory and copy the default configuration files if necessary. | ||
This function creates the configuration directory if it does not exist and copies the default | ||
configuration files to the configuration directory if they do not exist. Will not overwrite existing files. | ||
Notes | ||
----- | ||
This function is called before the main function to ensure that the configuration files are | ||
available before the application starts. | ||
""" | ||
|
||
# Setting the default configuration path | ||
default_config_dir = str(Path(dirname(__file__)).parent.absolute().joinpath('config')) | ||
|
||
# Ensuring configuration directory exists | ||
if not isdir(CONFIG_DIR): | ||
makedirs(CONFIG_DIR, exist_ok=True) | ||
|
||
# Copying the default configuration files to the config directory, if they do not exist | ||
if not exists(LOG_CONFIG_PATH): | ||
default_log_config = join(default_config_dir, basename(LOG_CONFIG_PATH)) | ||
shutil.copy(default_log_config, LOG_CONFIG_PATH) | ||
if not exists(CONFIG_PATH): | ||
default_config = join(default_config_dir, basename(CONFIG_PATH)) | ||
shutil.copy(default_config, CONFIG_PATH) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pip3 install --upgrade paho-mqtt |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='sentinel_mrhat_cam', | ||
name='sentinel-mrhat-cam', | ||
version='1.1.6', | ||
description='Testing python code for Starling detection project', | ||
author='Ferenc Nandor Janky, Attila Gombos, Nyiri Levente, Nyitrai Bence', | ||
author_email='[email protected]', | ||
packages=find_packages(), | ||
scripts=['scripts/sentinel_mrhat_cam.sh', 'scripts/sentinel_mrhat_cam_main.py'], | ||
data_files=[('config', ['config/config.json', 'config/log_config.yaml'])], | ||
install_requires=['picamera2', 'PyYAML>=6.0', 'pillow', 'pytz', 'paho-mqtt', 'numpy'], | ||
scripts=['bin/sentinel_mrhat_cam.sh', 'bin/sentinel_mrhat_cam_main.py'], | ||
data_files=[('config', ['config/sentinel_app_config.json', 'config/sentinel_log_config.yaml'])], | ||
install_requires=['picamera2', 'PyYAML', 'pillow', 'pytz', 'paho-mqtt', 'numpy'], | ||
) |