From 06331f4a8397660f6ec802bab6e419a8c34a248a Mon Sep 17 00:00:00 2001 From: George Lacey Date: Tue, 4 May 2021 05:17:11 +0100 Subject: [PATCH] Create standalone borg classes --- src/borg/__init__.py | 3 +++ src/borg/archive.py | 21 +++++++++++++++++++++ src/borg/repo.py | 20 ++++++++++++++++++++ src/borg/stats.py | 18 ++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 src/borg/__init__.py create mode 100644 src/borg/archive.py create mode 100644 src/borg/repo.py create mode 100644 src/borg/stats.py diff --git a/src/borg/__init__.py b/src/borg/__init__.py new file mode 100644 index 0000000..5d9807d --- /dev/null +++ b/src/borg/__init__.py @@ -0,0 +1,3 @@ +from .repo import Repo +from .archive import Archive +from .stats import Stats diff --git a/src/borg/archive.py b/src/borg/archive.py new file mode 100644 index 0000000..3a3ec1b --- /dev/null +++ b/src/borg/archive.py @@ -0,0 +1,21 @@ +from datetime import datetime + + +class Archive(object): + def __init__(self, fingerprint: str, name: str, start: datetime, end: datetime): + self.fingerprint = fingerprint + self.name = name + self.start = start + self.end = end + + @classmethod + def from_json(cls, json: dict): + uuid = json['id'] + name = json['name'] + start = datetime.fromisoformat(json['start']) + end = datetime.fromisoformat(json['end']) + return cls(uuid, name, start, end) + + @classmethod + def from_sql(cls, sql: list): + pass diff --git a/src/borg/repo.py b/src/borg/repo.py new file mode 100644 index 0000000..7187378 --- /dev/null +++ b/src/borg/repo.py @@ -0,0 +1,20 @@ +from datetime import datetime +from pathlib import Path + + +class Repo(object): + def __init__(self, fingerprint: str, location: Path, last_modified: datetime): + self.fingerprint = fingerprint + self.location = location + self.last_modified = last_modified + + @classmethod + def from_json(cls, json: dict): + uuid = json['id'] + location = Path(json['location']) + last_modified = datetime.fromisoformat(json['last_modified']) + return cls(uuid, location, last_modified) + + @classmethod + def from_sql(cls, sql: list): + pass \ No newline at end of file diff --git a/src/borg/stats.py b/src/borg/stats.py new file mode 100644 index 0000000..e4e19d4 --- /dev/null +++ b/src/borg/stats.py @@ -0,0 +1,18 @@ +class Stats(object): + def __init__(self, file_count: int, original_size: int, compressed_size: int, deduplicated_size: int): + self.file_count = file_count + self.original_size = original_size + self.compressed_size = compressed_size + self.deduplicated_size = deduplicated_size + + @classmethod + def from_json(cls, json: dict): + file_count = json['nfiles'] + original_size = json['original_size'] + compressed_size = json['compressed_size'] + deduplicated_size = json['deduplicated_size'] + return cls(file_count, original_size, compressed_size, deduplicated_size) + + @classmethod + def from_sql(cls, sql: list): + pass \ No newline at end of file