From c9b413be5c601f9685a58b5cbffef48c53a7adeb Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 6 Dec 2023 14:41:55 +0100 Subject: [PATCH 1/2] improve daemon start --- config.py | 18 ++++++++++++++++++ media_sync_daemon.py | 27 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 43d5a45..2100183 100644 --- a/config.py +++ b/config.py @@ -6,6 +6,8 @@ License: MIT """ +import pathlib + from dynaconf import Dynaconf config = Dynaconf( @@ -45,3 +47,19 @@ def validate_config(config): for ref in config.references: if not all(hasattr(ref, attr) for attr in ['file', 'table', 'local_path_column', 'driver_path_column']): raise ConfigError("Config error: Incorrect media reference settings") + + +def update_config_path( + path_param: str, +) -> None: + config_file_path = pathlib.Path(path_param) + + if config_file_path.exists(): + print(f"Using config file: {path_param}") + user_file_config = Dynaconf( + envvar_prefix=False, + settings_files=[config_file_path], + ) + config.update(user_file_config) + else: + raise IOError(f"Config file {config_file_path} does not exist.") diff --git a/media_sync_daemon.py b/media_sync_daemon.py index b66909d..1315568 100644 --- a/media_sync_daemon.py +++ b/media_sync_daemon.py @@ -6,18 +6,43 @@ License: MIT """ +import argparse +import sys import datetime import os import time from drivers import DriverError, create_driver from media_sync import create_mergin_client, mc_download, media_sync_push, mc_pull, MediaSyncError -from config import config, validate_config, ConfigError +from config import config, validate_config, ConfigError, update_config_path from version import __version__ def main(): + parser = argparse.ArgumentParser( + prog="media_sync_deamon.py", + description="Synchronization tool for media files in Mergin Maps project to other backends.", + epilog="www.merginmaps.com", + ) + + parser.add_argument( + "config_file", + nargs="?", + default="config.yaml", + help="Path to file with configuration. Default value is config.yaml in current working directory.", + ) + + args = parser.parse_args() + print(f"== Starting Mergin Media Sync daemon version {__version__} ==") + + try: + update_config_path(args.config_file) + except IOError as e: + print("Error:" + str(e)) + sys.exit(1) + sleep_time = config.as_int("daemon.sleep_time") + try: validate_config(config) except ConfigError as e: From 0fcb78630ad284403bee4095b3f2db1595cd3a25 Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Thu, 7 Dec 2023 12:33:13 +0100 Subject: [PATCH 2/2] Update media_sync_daemon.py --- media_sync_daemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media_sync_daemon.py b/media_sync_daemon.py index 1315568..f5c451e 100644 --- a/media_sync_daemon.py +++ b/media_sync_daemon.py @@ -19,7 +19,7 @@ def main(): parser = argparse.ArgumentParser( - prog="media_sync_deamon.py", + prog="media_sync_daemon.py", description="Synchronization tool for media files in Mergin Maps project to other backends.", epilog="www.merginmaps.com", )