Skip to content

Commit

Permalink
Merge branch 'main' into ci_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Caha committed Mar 20, 2024
2 parents 4dd5507 + 0fcb786 commit 1a054c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
18 changes: 18 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
License: MIT
"""

import pathlib

from dynaconf import Dynaconf

config = Dynaconf(
Expand Down Expand Up @@ -55,3 +57,19 @@ def validate_config(config):
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.")
29 changes: 26 additions & 3 deletions media_sync_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
License: MIT
"""

import argparse
import sys
import datetime
import os
import time
Expand All @@ -22,8 +24,31 @@


def main():
parser = argparse.ArgumentParser(
prog="media_sync_daemon.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:
Expand Down Expand Up @@ -59,9 +84,7 @@ def main():
media_sync_push(mc, driver, files_to_sync)

# check mergin client token expiration
delta = mc._auth_session["expire"] - datetime.datetime.now(
datetime.timezone.utc
)
delta = mc._auth_session["expire"] - datetime.datetime.now(datetime.timezone.utc)
if delta.total_seconds() < 3600:
mc = create_mergin_client()

Expand Down

0 comments on commit 1a054c8

Please sign in to comment.