sadrive.helpers.dbf module#
Database operations module for the CLI application.
This module manages SQLite connection, schema initialization, and CRUD operations for file mappings and service account size tracking.
Provides: - Connection management - Table creation for file_map and sa_size_map - Insert, update, delete, and query functions for file entries - Service account size tracking and management - Utility functions for searching and space reporting
- sadrive.helpers.dbf.add_size(sa_num: str, size: int, syncing: bool = False)[source]#
Updates a service account’s size, adding or syncing.
- Parameters:
sa_num – ID of the account to update.
size – Size change in bytes.
syncing – If True, sets size exactly to ‘size’.
- sadrive.helpers.dbf.delete_file(file_id: str)[source]#
Deletes a file record and subtracts its size from the service account.
- Parameters:
file_id – ID of the file to remove.
- sadrive.helpers.dbf.find_children(parent_id: str)[source]#
Lists file_map entries with the given parent_id.
- Parameters:
parent_id – Parent folder identifier.
- Returns:
File records under the parent.
- Return type:
list of dict
- sadrive.helpers.dbf.folder_exists(name: str, parent_id: str)[source]#
Checks if a folder entry exists under a parent.
- Parameters:
name – Folder name to look for.
parent_id – Parent folder identifier.
- Returns:
Folder ID if exists, else None.
- Return type:
str or None
- sadrive.helpers.dbf.get_connection()[source]#
Opens a SQLite connection to the configured database.
- Returns:
Connection object with row_factory set to sqlite3.Row.
- Return type:
sqlite3.Connection
- sadrive.helpers.dbf.get_file_details(file_id: str)[source]#
Retrieves a file record by its ID.
- Parameters:
file_id – Unique identifier to look up.
- Returns:
File record fields, or None if not found.
- Return type:
dict
- sadrive.helpers.dbf.get_sa_num(email: str)[source]#
Finds a service account ID by its email.
- Parameters:
email – Client email to search.
- Returns:
Account ID if found.
- Return type:
str or None
- sadrive.helpers.dbf.get_sa_size_taken(sa_num: str)[source]#
Retrieves size and email for a given service account.
- Parameters:
sa_num – Service account identifier.
- Returns:
Record fields, or None if not found.
- Return type:
dict
- sadrive.helpers.dbf.get_size_map()[source]#
Retrieves all service account size records.
- Returns:
Each dict has ‘_id’, ‘size’, and ‘email’.
- Return type:
list of dict
- sadrive.helpers.dbf.insert_file(file_id: str, file_name: str, parent_id: str, file_size: int, type: str, service_acc_num: str, shared: bool)[source]#
Inserts a new file record into file_map and updates account size.
- Parameters:
file_id – Unique identifier of the file in Drive.
file_name – Name of the file.
parent_id – Parent folder identifier.
file_size – Size of the file in bytes.
type – “file” or “folder”.
service_acc_num – ID of the service account used.
shared – Whether the file is shared.
- sadrive.helpers.dbf.insert_size_map(sa_num: str, size: int = 0)[source]#
Inserts a new entry in sa_size_map with initial size and email from account file.
- Parameters:
sa_num – Service account identifier.
size – Initial size in bytes. Default is 0.
- sadrive.helpers.dbf.remove_size(sa_num: str, size: int)[source]#
Subtracts size from a service account’s recorded usage.
- Parameters:
sa_num – Account ID.
size – Bytes to subtract.
- sadrive.helpers.dbf.rename_file(file_id: str, new_file_name: str)[source]#
Updates the name of a file record.
- Parameters:
file_id – ID of the file to rename.
new_file_name – New name to assign.
- sadrive.helpers.dbf.search_for_file_contains(value: str)[source]#
Searches file_map for filenames containing a substring.
- Parameters:
value – Substring to search in file_name.
- Returns:
Matching file records.
- Return type:
list of dict
Marks a file as shared or unshared.
- Parameters:
file_id – ID of the file.
shared – True to mark shared, False otherwise.