api(deltachat-rpc-client): make it possible to clone accounts

This commit is contained in:
link2xt
2025-03-09 17:37:19 +00:00
committed by l
parent 35d4eb5168
commit 82573dc78c
4 changed files with 19 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING, Optional, Union
from warnings import warn
@@ -38,6 +40,16 @@ class Account:
"""Remove the account."""
self._rpc.remove_account(self.id)
def clone(self) -> "Account":
"""Clone given account."""
with TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
self.export_backup(tmp_path)
files = list(tmp_path.glob("*.tar"))
new_account = self.manager.add_account()
new_account.import_backup(files[0])
return new_account
def start_io(self) -> None:
"""Start the account I/O."""
self._rpc.start_io(self.id)