Skip to content

Commit

Permalink
Fixed - s6 sequence, moved logger to file, failing tests (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarons authored Jun 25, 2024
1 parent c5fe1eb commit 2efa63d
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 11 deletions.
Empty file.
Empty file.
3 changes: 1 addition & 2 deletions root/etc/s6-overlay/s6-rc.d/svc-icd/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
# shellcheck shell=bash


exec \
s6-setuidgid abc /app/init.sh
exec s6-setuidgid abc /app/init.sh
1 change: 0 additions & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = (
Expand Down
4 changes: 3 additions & 1 deletion src/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
4 changes: 3 additions & 1 deletion src/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 4 additions & 1 deletion src/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
DEFAULT_COOKIE_DIRECTORY,
ENV_CONFIG_FILE_PATH_KEY,
ENV_ICLOUD_PASSWORD_KEY,
LOGGER,
config_parser,
get_logger,
notify,
read_config,
sync_drive,
sync_photos,
)
from src.usage import alive

LOGGER = get_logger()


def get_api_instance(
username,
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion src/sync_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion src/sync_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
)
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions tests/test_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2efa63d

Please sign in to comment.