sadrive.commands.upload module#
Handles uploading files and directories to SA-Drive, including:
Splitting large files across multiple service accounts based on available space
Preparing and writing “.sapart” parts and manifest files for oversized uploads
Reflecting local directory structures on the remote Drive
Concurrent uploading with progress tracking via Rich
Recursive and single-file upload commands integrated with Click
Key components: - prepare_sapart_jobs: Divides a large file into parts and records upload jobs - upload_file: Streams a file or part to Drive with real-time progress updates - sem_upload_wrapper: Ensures semaphore-based concurrency control for threads - reflect_structure_on_sadrive: Mirrors a local directory tree to remote folders - upload command: CLI entry point orchestrating directory or file uploads
- class sadrive.commands.upload.UploadThread(group: Any = None, target: Any = None, name: Any = None, args: Any = (), kwargs: Any = {})[source]#
Bases:
ThreadThread subclass that captures the return value of its target function.
- _return#
The value returned by the target function after execution.
- sadrive.commands.upload.prepare_sapart_jobs(file_path: str, total_size: int, parent_folder_id: str) list[tuple[str, int, str, str]][source]#
Prepare split-upload jobs for a large file that exceeds single-account capacity.
- Parameters:
file_path – Local filesystem path to the source file.
total_size – Total size of the source file in bytes.
parent_folder_id – Drive folder ID where the parts will be uploaded.
- Returns:
part_file_path (str): Path to the generated part file.
part_size (int): Size of this part in bytes.
service_account_id (str): ID of the service account chosen for this part.
remote_folder_id (str): Drive folder ID for uploading this part.
- Return type:
List of tuples describing each upload job. Each tuple contains
- sadrive.commands.upload.reflect_structure_on_sadrive(structure: Dict[str, Dict[str, DirTree | int] | int], destination: str, parent_id_map: list[tuple[str, int, str]], tmp_drive: SADrive, path: list[str])[source]#
Recursively reflect a local directory tree structure on SA-Drive by creating folders and scheduling file uploads.
- Parameters:
structure – Nested dictionary mapping folder names to subtrees or file sizes.
destination – Drive folder ID where this level’s content should be mirrored.
parent_id_map – List tracking tuples of (folder_name, local_size, drive_folder_id) for created folders.
tmp_drive – Authenticated SADrive instance used for folder creation.
path – Accumulated list of path segments representing the current traversal.
- Behavior:
Iterates through the structure dict: - For sub-dictionaries, creates a corresponding folder on Drive, updates parent_id_map, and recurses. - For file entries (size values), schedules upload jobs for each file part.
Does not perform actual uploads; integrates with the main upload command logic.
- sadrive.commands.upload.sem_upload_wrapper(fp: str, sz: int, pid: str, progress: Progress, task_id: int, sa: str)[source]#
Wrapper for uploading a file that ensures semaphore release after completion.
- Parameters:
fp – Local file path to upload.
sz – File size in bytes.
pid – Drive parent folder ID.
progress – Rich Progress instance for tracking upload progress.
task_id – Identifier for the progress task.
sa – Service account ID to use for this upload.
- Behavior:
Calls upload_file with provided arguments.
Ensures the global sem is released even if an error occurs.
- sadrive.commands.upload.upload_file(file_path: str, size: int, parent_folder_id: str, progress: Progress, task_id: int, sa_num_provided: str = '') Dict[str, str | int][source]#
Upload a file or part to SA-Drive, streaming with progress tracking.
- Parameters:
file_path – Local path to the file or part to upload.
size – Total size of the upload in bytes.
parent_folder_id – Drive folder ID where the file will be stored.
progress – Rich Progress instance for updating the progress bar.
task_id – Task identifier for Rich progress updates.
sa_num_provided – Optional service account ID to use; if empty, choose automatically.
- Returns:
Dict containing details of the uploaded file from the Drive API response, including ‘id’, ‘title’, ‘parents’, and ‘fileSize’.