(
env: Environment,
repo: str | None,
config: str | None,
workdir: str,
unsafe_tar_extract: bool,
)
| 378 | @pass_env |
| 379 | @handle_api_exception(logger) |
| 380 | def dump( |
| 381 | env: Environment, |
| 382 | repo: str | None, |
| 383 | config: str | None, |
| 384 | workdir: str, |
| 385 | unsafe_tar_extract: bool, |
| 386 | ): |
| 387 | workdir_path = pathlib.Path(workdir) |
| 388 | inbox_doc = load_inbox_doc(config) |
| 389 | |
| 390 | if not hasattr(tarfile, "data_filter") and not unsafe_tar_extract: |
| 391 | logger.error( |
| 392 | "You need to use Python >= 3.11 in order to safely unpack the downloaded tar file, or you need to pass " |
| 393 | "in --unsafe-tar-extract argument to allow unsafe tar file extracting" |
| 394 | ) |
| 395 | sys.exit(-1) |
| 396 | config = ensure_auth_config(api_base_url=env.api_base_url, repo=repo) |
| 397 | |
| 398 | inbox_emails = fetch_all_emails(env=env, config=config) |
| 399 | missing_email_output_files = list( |
| 400 | compute_missing_emails( |
| 401 | inbox_doc=inbox_doc, inbox_emails=inbox_emails, workdir_path=workdir_path |
| 402 | ) |
| 403 | ) |
| 404 | if not missing_email_output_files: |
| 405 | logger.info("No missing emails found, no need to update") |
| 406 | return |
| 407 | |
| 408 | private_key = PrivateKey.generate() |
| 409 | public_key = private_key.public_key.encode(URLSafeBase64Encoder).decode("ascii") |
| 410 | |
| 411 | with make_auth_client(base_url=env.api_base_url, token=config.token) as client: |
| 412 | client.raise_on_unexpected_status = True |
| 413 | # TODO: it's a bit slow to download all the emails in one request if there are tons of emails. |
| 414 | # maybe it makes more sense to break it down to smaller requests and stream line it? |
| 415 | resp: CreateInboxDumpRequestResponse = create_inbox_dump_request.sync( |
| 416 | body=CreateInboxDumpRequest( |
| 417 | public_key=public_key, |
| 418 | email_ids=[ |
| 419 | inbox_email.id for inbox_email, _ in missing_email_output_files |
| 420 | ], |
| 421 | ), |
| 422 | username=config.username, |
| 423 | repo_name=config.repo, |
| 424 | client=client, |
| 425 | ) |
| 426 | dump_id = resp.id |
| 427 | logger.info( |
| 428 | "Created dump [green]%s[/] with public_key [green]%s[/], email_count=[green]%s[/], workdir=[green]%s[/], waiting for updates ...", |
| 429 | dump_id, |
| 430 | public_key, |
| 431 | len(missing_email_output_files), |
| 432 | workdir_path, |
| 433 | extra={"markup": True, "highlighter": None}, |
| 434 | ) |
| 435 | |
| 436 | while True: |
| 437 | time.sleep(5) |
nothing calls this directly
no test coverage detected