diff --git a/root/etc/s6-overlay/s6-rc.d/init-icd-config/dependencies.d/init-config b/root/etc/s6-overlay/s6-rc.d/init-icd-config/dependencies.d/init-config new file mode 100644 index 00000000..e69de29b diff --git a/root/etc/s6-overlay/s6-rc.d/svc-icd/dependencies.d/init-services b/root/etc/s6-overlay/s6-rc.d/svc-icd/dependencies.d/init-services new file mode 100644 index 00000000..e69de29b diff --git a/root/etc/s6-overlay/s6-rc.d/svc-icd/run b/root/etc/s6-overlay/s6-rc.d/svc-icd/run index b5937e7f..7a8b9126 100755 --- a/root/etc/s6-overlay/s6-rc.d/svc-icd/run +++ b/root/etc/s6-overlay/s6-rc.d/svc-icd/run @@ -2,5 +2,4 @@ # shellcheck shell=bash -exec \ - s6-setuidgid abc /app/init.sh \ No newline at end of file +exec s6-setuidgid abc /app/init.sh \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py index 2a0e6ae1..94990ded 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -31,7 +31,6 @@ def read_config(config_path=DEFAULT_CONFIG_FILE_PATH): if not (config_path and os.path.exists(config_path)): print(f"Config file not found at {config_path}.") return None - print(f"Loading config from {config_path} ...") with open(file=config_path, encoding="utf-8") as config_file: config = YAML().load(config_file) config["app"]["credentials"]["username"] = ( diff --git a/src/config_parser.py b/src/config_parser.py index 792d37de..954cbd6f 100644 --- a/src/config_parser.py +++ b/src/config_parser.py @@ -11,9 +11,11 @@ DEFAULT_RETRY_LOGIN_INTERVAL_SEC, DEFAULT_ROOT_DESTINATION, DEFAULT_SYNC_INTERVAL_SEC, - LOGGER, + get_logger, ) +LOGGER = get_logger() + def config_path_to_string(config_path): """Build config path as string.""" diff --git a/src/notify.py b/src/notify.py index 957ba0d8..cda37ecc 100644 --- a/src/notify.py +++ b/src/notify.py @@ -4,9 +4,11 @@ import requests -from src import LOGGER, config_parser +from src import config_parser, get_logger from src.email_message import EmailMessage as Message +LOGGER = get_logger() + def notify_telegram(config, message, last_send=None, dry_run=False): """Send telegram notification.""" diff --git a/src/sync.py b/src/sync.py index 79a34ae6..2bc7d03f 100644 --- a/src/sync.py +++ b/src/sync.py @@ -11,8 +11,8 @@ DEFAULT_COOKIE_DIRECTORY, ENV_CONFIG_FILE_PATH_KEY, ENV_ICLOUD_PASSWORD_KEY, - LOGGER, config_parser, + get_logger, notify, read_config, sync_drive, @@ -20,6 +20,8 @@ ) from src.usage import alive +LOGGER = get_logger() + def get_api_instance( username, @@ -53,6 +55,7 @@ def sync(): drive_sync_interval = 0 photos_sync_interval = 0 sleep_for = 10 + while True: config = read_config( config_path=os.environ.get( diff --git a/src/sync_drive.py b/src/sync_drive.py index 510ab980..b81a0837 100644 --- a/src/sync_drive.py +++ b/src/sync_drive.py @@ -13,7 +13,9 @@ import magic from icloudpy import exceptions -from src import LOGGER, config_parser +from src import config_parser, get_logger + +LOGGER = get_logger() def wanted_file(filters, ignore, file_path): diff --git a/src/sync_photos.py b/src/sync_photos.py index 647d5536..1d631a18 100644 --- a/src/sync_photos.py +++ b/src/sync_photos.py @@ -9,8 +9,9 @@ from icloudpy import exceptions -from src import LOGGER, config_parser +from src import config_parser, get_logger +LOGGER = get_logger() original_alt_filetype_to_extension = { "public.png": "png", "public.jpeg": "jpeg", diff --git a/src/usage.py b/src/usage.py index a033bcef..c12a7dbb 100644 --- a/src/usage.py +++ b/src/usage.py @@ -7,7 +7,7 @@ from src.config_parser import prepare_root_destination -CACHE_FILE_NAME = ".data" +CACHE_FILE_NAME = "/config/.data" NEW_INSTALLATION_ENDPOINT = os.environ.get("NEW_INSTALLATION_ENDPOINT", None) NEW_HEARTBEAT_ENDPOINT = os.environ.get("NEW_HEARTBEAT_ENDPOINT", None) APP_NAME = "icloud-drive-docker" diff --git a/tests/test_sync.py b/tests/test_sync.py index cb287148..bcee6016 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -86,7 +86,7 @@ def test_sync_photos_only( mock_read_config.return_value = config self.assertIsNone(sync.sync()) dir_length = len(os.listdir(self.root_dir)) - self.assertTrue(2 == dir_length) + self.assertTrue(1 == dir_length) self.assertTrue( os.path.isdir(os.path.join(self.root_dir, config["photos"]["destination"])) ) @@ -120,7 +120,7 @@ def test_sync_drive_only( os.path.isdir(os.path.join(self.root_dir, config["drive"]["destination"])) ) dir_length = len(os.listdir(self.root_dir)) - self.assertTrue(2 == dir_length) + self.assertTrue(1 == dir_length) @patch(target="keyring.get_password", return_value=data.VALID_PASSWORD) @patch( diff --git a/tests/test_usage.py b/tests/test_usage.py index 58cc41a1..05b305e6 100644 --- a/tests/test_usage.py +++ b/tests/test_usage.py @@ -16,6 +16,9 @@ def setUp(self) -> None: """Set up test.""" self.new_installation_data = dict(usage.NEW_INSTALLATION_DATA) self.config = read_config(config_path=tests.CONFIG_PATH) + file_path = usage.init_cache(config=self.config) + if os.path.isfile(file_path): + os.remove(file_path) return super().setUp() def tearDown(self) -> None: