-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkopiaapi.py
28 lines (22 loc) · 834 Bytes
/
kopiaapi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import json
import subprocess
class KopiaApi:
def __init__(self, config_file:str):
self._config_file = config_file
def _kopia_command(self, args:list[str]):
args.append(f"--config-file={self._config_file}")
with subprocess.Popen(["kopia", *args], stdout=subprocess.PIPE) as proc:
res = proc.stdout.read()
return json.loads(res)
def get_repo_status(self) -> dict:
args = ["repo", "status", "--json"]
status = self._kopia_command(args)
return status
def get_snapshot_list(self) -> list:
args = ["snapshot", "list", "--json"]
snapshots = self._kopia_command(args)
return snapshots
def get_show_obj(self, obj_id) -> dict:
args = ["show", obj_id ]
show = self._kopia_command(args)
return show