wip
This commit is contained in:
@ -217,9 +217,8 @@ class Thinner:
|
|||||||
|
|
||||||
# NOTE: this should inherit from (object) to function correctly with python 2.7
|
# NOTE: this should inherit from (object) to function correctly with python 2.7
|
||||||
class CachedProperty(object):
|
class CachedProperty(object):
|
||||||
""" A property that is only computed once per instance and then replaces
|
""" A property that is only computed once per instance and
|
||||||
itself with an ordinary attribute. Deleting the attribute resets the
|
then stores the result in _cached_properties of the object.
|
||||||
property.
|
|
||||||
|
|
||||||
Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76
|
Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76
|
||||||
"""
|
"""
|
||||||
@ -228,6 +227,7 @@ class CachedProperty(object):
|
|||||||
self.__doc__ = getattr(func, '__doc__')
|
self.__doc__ = getattr(func, '__doc__')
|
||||||
self.func = func
|
self.func = func
|
||||||
|
|
||||||
|
|
||||||
def __get__(self, obj, cls):
|
def __get__(self, obj, cls):
|
||||||
if obj is None:
|
if obj is None:
|
||||||
return self
|
return self
|
||||||
@ -244,6 +244,10 @@ class CachedProperty(object):
|
|||||||
return obj._cached_properties[propname]
|
return obj._cached_properties[propname]
|
||||||
|
|
||||||
|
|
||||||
|
def invalidate_cache(obj):
|
||||||
|
obj._cached_properties = {}
|
||||||
|
|
||||||
|
|
||||||
class Logger:
|
class Logger:
|
||||||
|
|
||||||
# simple logging stubs
|
# simple logging stubs
|
||||||
@ -535,7 +539,7 @@ class ZfsDataset:
|
|||||||
self.zfs_node = zfs_node
|
self.zfs_node = zfs_node
|
||||||
self.name = name # full name
|
self.name = name # full name
|
||||||
self.force_exists = force_exists
|
self.force_exists = force_exists
|
||||||
self._cached_properties = {}
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{}: {}".format(self.zfs_node, self.name)
|
return "{}: {}".format(self.zfs_node, self.name)
|
||||||
@ -561,7 +565,7 @@ class ZfsDataset:
|
|||||||
def invalidate(self):
|
def invalidate(self):
|
||||||
"""clear cache"""
|
"""clear cache"""
|
||||||
# TODO: nicer?
|
# TODO: nicer?
|
||||||
self._cached_properties = {}
|
invalidate_cache(self)
|
||||||
self.force_exists = None
|
self.force_exists = None
|
||||||
|
|
||||||
def split_path(self):
|
def split_path(self):
|
||||||
@ -769,6 +773,11 @@ class ZfsDataset:
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def add_virtual_snapshot(self, snapshot):
|
||||||
|
"""add to self.snapshots as soon as it is created"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@CachedProperty
|
@CachedProperty
|
||||||
def snapshots(self):
|
def snapshots(self):
|
||||||
"""get all snapshots of this dataset"""
|
"""get all snapshots of this dataset"""
|
||||||
@ -1452,7 +1461,8 @@ class ZfsNode(ExecuteNode):
|
|||||||
dataset.verbose("No changes since {}".format(dataset.our_snapshots[-1].snapshot_name))
|
dataset.verbose("No changes since {}".format(dataset.our_snapshots[-1].snapshot_name))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
snapshot = ZfsDataset(dataset.zfs_node, dataset.name + "@" + snapshot_name)
|
#force_exist, since we're making it
|
||||||
|
snapshot = ZfsDataset(dataset.zfs_node, dataset.name + "@" + snapshot_name, force_exists=True)
|
||||||
|
|
||||||
pool = dataset.split_path()[0]
|
pool = dataset.split_path()[0]
|
||||||
if pool not in pools:
|
if pool not in pools:
|
||||||
|
|||||||
Reference in New Issue
Block a user