Coverage for src/drive_folder_processing.py: 100%
20 statements
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-12 17:18 +0000
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-12 17:18 +0000
1"""Folder processing utilities.
3This module provides folder creation and processing functionality for
4iCloud Drive sync operations, separating folder logic from sync operations per SRP.
5"""
7__author__ = "Mandar Patil (mandarons@pm.me)"
9import os
10import unicodedata
11from typing import Any
12from urllib.parse import unquote
14from src import configure_icloudpy_logging, get_logger
15from src.drive_filtering import wanted_folder
17# Configure icloudpy logging immediately after import
18configure_icloudpy_logging()
20LOGGER = get_logger()
23def process_folder(
24 item: Any,
25 destination_path: str,
26 filters: list[str] | None,
27 ignore: list[str] | None,
28 root: str,
29) -> str | None:
30 """Process a folder item by creating the local directory if wanted.
32 Args:
33 item: iCloud folder item
34 destination_path: Local destination directory
35 filters: Folder filters to apply
36 ignore: Ignore patterns
37 root: Root directory for relative path calculations
39 Returns:
40 Path to the created directory, or None if folder should be skipped
41 """
42 if not (item and destination_path and root):
43 return None
45 # Decode URL-encoded folder name from iCloud API
46 # This handles special characters like %CC%88 (combining diacritical marks)
47 decoded_name = unquote(item.name)
48 new_directory = os.path.join(destination_path, decoded_name)
49 new_directory_norm = unicodedata.normalize("NFC", new_directory)
51 if not wanted_folder(filters=filters, ignore=ignore, folder_path=new_directory_norm, root=root):
52 LOGGER.debug(f"Skipping the unwanted folder {new_directory} ...")
53 return None
55 os.makedirs(new_directory_norm, exist_ok=True)
56 return new_directory