sadrive.helpers.utils module#
This module provides helper functions and utilities for the CLI application. It uses service account storage for Google Drive operations and offers:
Configuration directory handling
Path construction for accounts and database
Rclone configuration initialization
Human-readable byte and time formatting
List partitioning
Generator wrapper
Service account selection by free space
Directory tree mapping
File size measurement
Filename shortening
Constants: - CONFIG_POINTER: Path to the file storing the config directory pointer - MAGIC_SIZE: Total capacity threshold for service accounts (in bytes) - BUFFER: Buffer size threshold (in bytes) - MAX_THREADS: Maximum number of threads permitted
- class sadrive.helpers.utils.FF(name: str, file_id: str, parent_id: str, type: str)[source]#
Bases:
objectRepresents a file or folder entry in Google Drive.
- name#
The display name of the file or folder.
- file_id#
The unique identifier in Drive.
- parent_id#
The parent folder’s identifier.
- type#
The entry type, e.g. ‘folder’ or ‘file’.
- class sadrive.helpers.utils.Generator(gen: Any)[source]#
Bases:
objectWrapper to enable ‘yield from’ for a generator function.
- gen#
The underlying generator.
- class sadrive.helpers.utils.Manifest[source]#
Bases:
TypedDictManifest describing an original file and its parts.
- original_filename#
The original filename before splitting.
- Type:
str
- parts#
A list of PartInfo dictionaries for each part.
- Type:
- original_filename: str#
- class sadrive.helpers.utils.PartInfo[source]#
Bases:
TypedDictInformation about a part of a split file.
- filename#
Name of the file part.
- Type:
str
- size#
Size of the file part in bytes.
- Type:
int
- filename: str#
- size: int#
- sadrive.helpers.utils.get_accounts_path() Path[source]#
Constructs the path to the ‘accounts’ subdirectory within the config directory.
- Returns:
Path to the service accounts directory.
- Return type:
Path
- sadrive.helpers.utils.get_config_dir()#
- sadrive.helpers.utils.get_database_path() Path[source]#
Constructs the path to the SQLite database file within the config directory.
- Returns:
Path to the ‘database.db’ file.
- Return type:
Path
- sadrive.helpers.utils.get_dir_structure(path: Path) Dict[str, Dict[str, DirTree | int] | int][source]#
Recursively builds a directory tree mapping folder names to subtrees or file sizes.
- Parameters:
path – Root directory path.
- Returns:
Nested dict mapping names to file sizes or further DirTrees.
- Return type:
DirTree
- sadrive.helpers.utils.get_file_size(file_path: Path)[source]#
Returns the size of a file in bytes by seeking to its end.
- Parameters:
file_path – Path to the target file.
- Returns:
File size in bytes.
- Return type:
int
- sadrive.helpers.utils.get_free_sa(sa_map: List[dict[str, Any]], file_size: int)[source]#
Selects service account IDs with enough free space.
- Parameters:
sa_map – List of dicts containing ‘_id’ and ‘size’ keys.
file_size – Required file size in bytes.
- Returns:
Sorted list of account IDs that can accommodate the file.
- Return type:
List[int]
- sadrive.helpers.utils.get_gclone_exe() Path[source]#
Reads and returns the path to the gclone executable from config.json.
- Returns:
Path to the ‘gclone’ executable.
- Return type:
Path
- sadrive.helpers.utils.get_parent_id() str[source]#
Reads and returns the parent folder ID from config.json.
- Returns:
The ‘parent_id’ value stored in config.json.
- Return type:
str
- sadrive.helpers.utils.humanbytes(size: float) str[source]#
Converts a size in bytes to a human-readable string.
- Parameters:
size – Size in bytes.
- Returns:
Formatted size (e.g. ‘1.234 MiB’).
- Return type:
str
- sadrive.helpers.utils.humantime(seconds: int)[source]#
Formats a duration in seconds into HhMmSs or MmSs.
- Parameters:
seconds – Duration in seconds.
- Returns:
Formatted time string.
- Return type:
str
- sadrive.helpers.utils.list_into_n_parts(lst: List[T], n: int) List[List[T]][source]#
Splits a list into n approximately equal parts.
- Parameters:
lst – List of items to split.
n – Number of parts.
- Returns:
A list containing n sublists.
- Return type:
List[List[T]]