radiens_data_catalog.drive
Google Drive API interactions: scanning, file download and upload planning.
Each xdat recording is three files sharing a base_name:
| CLASS | DESCRIPTION |
|---|---|
DriveItem |
A single item returned by the Drive API |
DriveItemEntry |
One non-recording Drive item stored in the catalog. |
DriveService |
The part of the Drive API v3 service this package calls. |
RecordingEntry |
One xdat recording dataset stored in the catalog. |
UploadPlan |
What an upload of one local folder will do, worked out before anything is sent. |
| FUNCTION | DESCRIPTION |
|---|---|
download_item |
Download a Drive item (file or folder) mirroring the Drive path locally. |
download_meta |
Download only a recording's |
download_recording |
Download the xdat files for a recording into a path-mirrored local directory. |
local_md5 |
Return the hex MD5 of a local file, the digest Drive reports as |
plan_upload |
Work out how to upload |
scan_drive |
Recursively scan Drive and return xdat recordings and all other items. |
scan_drive_flat |
Scan Drive without traversing from a root folder. |
xdat_recording_exists_locally |
Return |
Classes
DriveItem
DriveItemEntry
Bases: TypedDict
One non-recording Drive item stored in the catalog.
Represents a single file or folder found on Drive that is not part of
an xdat recording — for example a logs/ directory, a config file,
or a writeup. No structural or semantic classification is applied; the
consumer decides what these items mean.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
The file or folder name as it appears on Drive (e.g.
TYPE:
|
is_folder |
TYPE:
|
drive_path |
Slash-joined path from the root folder to the parent
folder of this item. Together with
TYPE:
|
drive_id |
Google Drive ID of this file or folder.
TYPE:
|
mime_type |
MIME type as reported by the Drive API.
TYPE:
|
local_path |
Absolute local path to the downloaded file or folder, or
TYPE:
|
upload_time |
ISO 8601
TYPE:
|
size |
Size in bytes as reported by Drive, or
TYPE:
|
DriveService
RecordingEntry
Bases: TypedDict
One xdat recording dataset stored in the catalog.
Represents a single neural recording. The three xdat files
(_data.xdat, .xdat.json, _timestamp.xdat) share a common
base_name stem and are treated as a single unit.
| ATTRIBUTE | DESCRIPTION |
|---|---|
base_name |
Shared filename stem across all three xdat files.
Note:
TYPE:
|
drive_path |
Slash-joined path from the root folder to the folder containing the recording files.
TYPE:
|
drive_file_ids |
Maps file type labels ( |
local_path |
Absolute path to the local directory where the recording
has been downloaded, or
TYPE:
|
upload_time |
ISO 8601
TYPE:
|
size |
Combined size in bytes of the constituent xdat files that
reported a size (summed from whichever of the three files Drive
reported a size for).
TYPE:
|
UploadPlan
dataclass
What an upload of one local folder will do, worked out before anything is sent.
Drive paths are relative to the catalog's root folder, like drive_path
in the catalog entries.
| ATTRIBUTE | DESCRIPTION |
|---|---|
drive_path |
Drive path the local folder lands at.
TYPE:
|
folder_ids |
Drive ID of each folder on the way that already exists,
keyed by Drive path ( |
folders_to_create |
Drive paths of missing folders, each after its parent. |
files_to_upload |
Each local file to send, with the Drive path of its folder. |
files_skipped |
Local files already on Drive with the same MD5. |
Functions
download_item
download_item(
service: DriveService,
item: DriveItemEntry,
local_data_dir: str,
quiet: bool = False,
progress_callback: ProgressCallback | None = None,
) -> str
Download a Drive item (file or folder) mirroring the Drive path locally.
Items are stored under {local_data_dir}/{drive_path}/{name}, keeping
them in the same local directory tree as recordings.
For folder items the entire subtree is downloaded recursively.
| PARAMETER | DESCRIPTION |
|---|---|
service
|
Authenticated Drive API service.
TYPE:
|
item
|
The :class:
TYPE:
|
local_data_dir
|
Root local data directory.
TYPE:
|
quiet
|
If
TYPE:
|
progress_callback
|
If given, called with the bytes received since the previous chunk across all files in this item.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The absolute path to the downloaded file or folder as a string. |
download_meta
download_meta(
service: DriveService, recording: RecordingEntry, dest_path: Path
) -> None
Download only a recording's .xdat.json metadata file to dest_path.
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the recording has no |
download_recording
download_recording(
service: DriveService,
recording: RecordingEntry,
local_data_dir: str,
quiet: bool = False,
progress_callback: ProgressCallback | None = None,
) -> str
Download the xdat files for a recording into a path-mirrored local directory.
Files are stored under {local_data_dir}/{drive_path}/, mirroring the
Drive folder hierarchy.
| PARAMETER | DESCRIPTION |
|---|---|
service
|
Authenticated Drive API service.
TYPE:
|
recording
|
The :class:
TYPE:
|
local_data_dir
|
Root local data directory.
TYPE:
|
quiet
|
If
TYPE:
|
progress_callback
|
If given, called with the bytes received since the previous chunk across all of this recording's files.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The absolute path to the directory where the files were written. |
local_md5
Return the hex MD5 of a local file, the digest Drive reports as md5Checksum.
plan_upload
plan_upload(
service: DriveService, root_folder_id: str, local_dir: Path, parent_drive_path: str
) -> UploadPlan
Work out how to upload local_dir to {parent_drive_path}/{local_dir.name} without changing Drive.
Missing folders on the way, parent_drive_path included, are planned for
creation. Where the target folder already exists, each local file is compared
with the remote file at the same path: absent means upload, the same MD5 means
skip, and anything else is a conflict. Files named in SKIPPED_UPLOAD_NAMES
are left out.
| PARAMETER | DESCRIPTION |
|---|---|
service
|
Authenticated Drive API service.
TYPE:
|
root_folder_id
|
Drive ID of the catalog's root folder.
TYPE:
|
local_dir
|
Local folder to upload.
TYPE:
|
parent_drive_path
|
Drive path, from the root, of the folder that receives
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
UploadPlan
|
The plan; nothing on Drive has changed. |
| RAISES | DESCRIPTION |
|---|---|
NotADirectoryError
|
If |
UploadConflictError
|
If anything at a target path differs from the local files, or a folder on the way is ambiguous. Lists every conflict. |
scan_drive
scan_drive(
service: DriveService,
root_folder_id: str,
*,
drive_path: str = "",
quiet: bool = False,
) -> tuple[list[RecordingEntry], list[DriveItemEntry]]
Recursively scan Drive and return xdat recordings and all other items.
Traverses the full subtree rooted at root_folder_id. The folder itself
gets no entry.
Recording collection: xdat files are recognized at any depth by their
suffix and merged by (drive_path, base_name) into
:class:RecordingEntry records. The three component files are treated as
a single unit.
Item collection: Every non-xdat file and every folder (at any depth)
is cataloged as a :class:DriveItemEntry. No depth-based filtering or
structural classification is applied — the consumer decides what items mean.
| PARAMETER | DESCRIPTION |
|---|---|
service
|
Authenticated Drive API service.
TYPE:
|
root_folder_id
|
Google Drive folder ID of the root folder to scan.
TYPE:
|
drive_path
|
Path of
TYPE:
|
quiet
|
Has no effect; this scanner shows no progress. It is accepted so both scanners take the same arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[list[RecordingEntry], list[DriveItemEntry]]
|
A tuple |
scan_drive_flat
scan_drive_flat(
service: DriveService, root_folder_id: str, *, quiet: bool = False
) -> tuple[list[RecordingEntry], list[DriveItemEntry]]
Scan Drive without traversing from a root folder.
Flat-lists every file in the root's Shared Drive, or every file visible to
the account when the root is in a My Drive, reconstructs folder paths
via the parents field, and applies the same classification rules as
:func:scan_drive: xdat files become :class:RecordingEntry records;
everything else becomes a :class:DriveItemEntry.
| PARAMETER | DESCRIPTION |
|---|---|
service
|
Authenticated Drive API service.
TYPE:
|
root_folder_id
|
The logical root folder ID — used as the stop sentinel when resolving paths.
TYPE:
|
quiet
|
Suppress the progress output.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[list[RecordingEntry], list[DriveItemEntry]]
|
Same |
xdat_recording_exists_locally
xdat_recording_exists_locally(recording: RecordingEntry, local_dir: str | Path) -> bool
Return True if all xdat files for a recording exist under local_dir.
| PARAMETER | DESCRIPTION |
|---|---|
recording
|
The catalog entry to check.
TYPE:
|
local_dir
|
Directory expected to contain the three xdat files. |
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |