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 | ||||
| class CachedProperty(object): | ||||
|     """ A property that is only computed once per instance and then replaces | ||||
|         itself with an ordinary attribute. Deleting the attribute resets the | ||||
|         property. | ||||
|     """ A property that is only computed once per instance and | ||||
|     then stores the result in _cached_properties of the object. | ||||
|  | ||||
|         Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76 | ||||
|         """ | ||||
| @ -228,6 +227,7 @@ class CachedProperty(object): | ||||
|         self.__doc__ = getattr(func, '__doc__') | ||||
|         self.func = func | ||||
|  | ||||
|  | ||||
|     def __get__(self, obj, cls): | ||||
|         if obj is None: | ||||
|             return self | ||||
| @ -244,6 +244,10 @@ class CachedProperty(object): | ||||
|         return obj._cached_properties[propname] | ||||
|  | ||||
|  | ||||
| def invalidate_cache(obj): | ||||
|     obj._cached_properties = {} | ||||
|  | ||||
|  | ||||
| class Logger: | ||||
|  | ||||
|     # simple logging stubs | ||||
| @ -535,7 +539,7 @@ class ZfsDataset: | ||||
|         self.zfs_node = zfs_node | ||||
|         self.name = name  # full name | ||||
|         self.force_exists = force_exists | ||||
|         self._cached_properties = {} | ||||
|  | ||||
|  | ||||
|     def __repr__(self): | ||||
|         return "{}: {}".format(self.zfs_node, self.name) | ||||
| @ -561,7 +565,7 @@ class ZfsDataset: | ||||
|     def invalidate(self): | ||||
|         """clear cache""" | ||||
|         # TODO: nicer? | ||||
|         self._cached_properties = {} | ||||
|         invalidate_cache(self) | ||||
|         self.force_exists = None | ||||
|  | ||||
|     def split_path(self): | ||||
| @ -769,6 +773,11 @@ class ZfsDataset: | ||||
|  | ||||
|         return ret | ||||
|  | ||||
|     def add_virtual_snapshot(self, snapshot): | ||||
|         """add to self.snapshots as soon as it is created""" | ||||
|         pass | ||||
|  | ||||
|  | ||||
|     @CachedProperty | ||||
|     def snapshots(self): | ||||
|         """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)) | ||||
|                 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] | ||||
|             if pool not in pools: | ||||
|  | ||||
		Reference in New Issue
	
	Block a user