Coverage for src/drive_folder_processing.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-16 04:41 +0000

1"""Folder processing utilities. 

2 

3This module provides folder creation and processing functionality for 

4iCloud Drive sync operations, separating folder logic from sync operations per SRP. 

5""" 

6 

7__author__ = "Mandar Patil (mandarons@pm.me)" 

8 

9import os 

10import unicodedata 

11from typing import Any 

12 

13from src import configure_icloudpy_logging, get_logger 

14from src.drive_filtering import wanted_folder 

15 

16# Configure icloudpy logging immediately after import 

17configure_icloudpy_logging() 

18 

19LOGGER = get_logger() 

20 

21 

22def process_folder( 

23 item: Any, 

24 destination_path: str, 

25 filters: list[str] | None, 

26 ignore: list[str] | None, 

27 root: str, 

28) -> str | None: 

29 """Process a folder item by creating the local directory if wanted. 

30 

31 Args: 

32 item: iCloud folder item 

33 destination_path: Local destination directory 

34 filters: Folder filters to apply 

35 ignore: Ignore patterns 

36 root: Root directory for relative path calculations 

37 

38 Returns: 

39 Path to the created directory, or None if folder should be skipped 

40 """ 

41 if not (item and destination_path and root): 

42 return None 

43 

44 new_directory = os.path.join(destination_path, item.name) 

45 new_directory_norm = unicodedata.normalize("NFC", new_directory) 

46 

47 if not wanted_folder(filters=filters, ignore=ignore, folder_path=new_directory_norm, root=root): 

48 LOGGER.debug(f"Skipping the unwanted folder {new_directory} ...") 

49 return None 

50 

51 os.makedirs(new_directory_norm, exist_ok=True) 

52 return new_directory