start introducing modules
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from re import search
|
||||
|
||||
from dataset import Dataset
|
||||
from zfs import ZFS
|
||||
from zfs_path import ZFSPath
|
||||
|
||||
|
||||
class Snapshot:
|
||||
def __init__(self, path: ZFSPath):
|
||||
self._path = path
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, qualified_name: str) -> Snapshot:
|
||||
return cls(ZFSPath.from_string(qualified_name))
|
||||
|
||||
def __gt__(self, other: Snapshot) -> bool:
|
||||
return self.snapshot_name > other.snapshot_name
|
||||
|
||||
def __repr__(self):
|
||||
return str(self._path)
|
||||
|
||||
def __eq__(self, other: Snapshot):
|
||||
return self._path == other._path
|
||||
|
||||
def newer_than(self, other: Snapshot) -> bool:
|
||||
return self > other
|
||||
|
||||
@property
|
||||
def snapshot_name(self) -> str:
|
||||
assert self._path.snapshot_name
|
||||
return self._path.snapshot_name
|
||||
|
||||
def matches_regex(self, regex: str) -> bool:
|
||||
"""Check if the qualified name of the snapshot matches a regular expression."""
|
||||
return bool(search(regex, str(self._path)))
|
||||
|
||||
def destroy(self) -> None:
|
||||
ZFS.destroy_snapshot(self)
|
||||
|
||||
@property
|
||||
def pool(self) -> str:
|
||||
return self._path.pool_name
|
||||
|
||||
@property
|
||||
def dataset(self) -> Dataset:
|
||||
return Dataset(self._path.dataset)
|
||||
Reference in New Issue
Block a user