services.google_drive_service module

services.google_drive_service.start_device_authorization(user_id)[מקור]

Starts OAuth Device Authorization flow for Google Drive.

Returns a dict with: verification_url, user_code, device_code, interval, expires_in.

Return type:

Dict[str, Any]

פרמטרים:

user_id (int)

services.google_drive_service.poll_device_token(device_code)[מקור]

Attempts a single token exchange for a device_code.

Return type:

Optional[Dict[str, Any]]

Returns:

  • dict with tokens on success

  • None if authorization is still pending or needs to slow down

  • dict with {”error“: <code>, ”error_description“: <str>} on user-facing errors

פרמטרים:

device_code (str)

services.google_drive_service.save_tokens(user_id, tokens)[מקור]

Save OAuth tokens, preserving existing refresh_token if missing.

Some OAuth exchanges (and refreshes) do not return refresh_token again. We merge with existing tokens to avoid wiping the refresh_token.

Return type:

bool

פרמטרים:
services.google_drive_service.get_drive_service(user_id)[מקור]
פרמטרים:

user_id (int)

services.google_drive_service.ensure_folder(user_id, name, parent_id=None)[מקור]
Return type:

Optional[str]

פרמטרים:
  • user_id (int)

  • name (str)

  • parent_id (str | None)

services.google_drive_service.get_or_create_default_folder(user_id)[מקור]
Return type:

Optional[str]

פרמטרים:

user_id (int)

services.google_drive_service.ensure_path(user_id, path)[מקור]

Ensure nested folders path like ”Parent/Sub1/Sub2“ exists; returns last folder id.

Return type:

Optional[str]

פרמטרים:
services.google_drive_service.ensure_subpath(user_id, sub_path)[מקור]

Ensure nested subfolders under the user’s root. Does not change prefs.

Return type:

Optional[str]

פרמטרים:
  • user_id (int)

  • sub_path (str)

services.google_drive_service.compute_subpath(category, repo_name=None)[מקור]

Return destination subpath under the user’s root folder.

Simplified structure without date-based nesting to avoid deep paths: - zip -> ”zip“ - all -> ”הכל“ - by_repo -> ”לפי_ריפו/<repo_name>“ - large -> ”קבצים_גדולים“ - other -> ”שאר_קבצים“

Return type:

str

פרמטרים:
  • category (str)

  • repo_name (str | None)

services.google_drive_service.compute_friendly_name(user_id, category, entity_name, rating=None, content_sample=None)[מקור]

Return a friendly filename per spec using underscores.

Pattern examples: - BKP_zip_CodeBot_v7_26-08-2025.zip - BKP_zip_CodeBot_v7_🏆_26-08-2025.zip

Return type:

str

פרמטרים:
  • user_id (int)

  • category (str)

  • entity_name (str)

  • rating (str | None)

  • content_sample (bytes | None)

services.google_drive_service.upload_bytes(user_id, filename, data, folder_id=None, sub_path=None)[מקור]
Return type:

Optional[str]

פרמטרים:
  • user_id (int)

  • filename (str)

  • data (bytes)

  • folder_id (str | None)

  • sub_path (str | None)

services.google_drive_service.upload_all_saved_zip_backups(user_id)[מקור]

Upload only ZIP backups that were not uploaded before for this user.

Uses db.drive_prefs.uploaded_backup_ids (set) to deduplicate uploads.

Return type:

Tuple[int, List[str]]

פרמטרים:

user_id (int)

services.google_drive_service.create_repo_grouped_zip_bytes(user_id)[מקור]

Return zips grouped by repo: (repo_name, suggested_name, zip_bytes).

Return type:

List[Tuple[str, str, bytes]]

פרמטרים:

user_id (int)

services.google_drive_service.create_full_backup_zip_bytes(user_id, category='all')[מקור]

Creates a ZIP of user data by category and returns (filename, bytes).

Return type:

Tuple[str, bytes]

פרמטרים:
  • user_id (int)

  • category (str)

services.google_drive_service.perform_scheduled_backup(user_id)[מקור]

Runs a scheduled backup to Drive according to user’s selected category.

Category resolution priority: 1) drive_prefs.schedule_category (explicit) 2) drive_prefs.last_selected_category (UI selection) 3) fallback to ”all“

Updates last_backup_at on any successful scheduled upload. Updates last_full_backup_at only if category == ”all“.

Return type:

bool

פרמטרים:

user_id (int)