summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugin/helpers.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-03-25 11:19:11 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-03-25 11:19:11 -0400
commit432f448983ff27452d82d62314d91c942f31bce5 (patch)
treef7f0aeb5f20e928306a37407857afe822713f5cb /src/lib/Bcfg2/Server/Plugin/helpers.py
parentfe7a3e9c7a7d66cccbd825465cefcf88165a0c3a (diff)
downloadbcfg2-432f448983ff27452d82d62314d91c942f31bce5.tar.gz
bcfg2-432f448983ff27452d82d62314d91c942f31bce5.tar.bz2
bcfg2-432f448983ff27452d82d62314d91c942f31bce5.zip
Packages: properly implemented deepcopy() for PackagesSources objects
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugin/helpers.py')
-rw-r--r--src/lib/Bcfg2/Server/Plugin/helpers.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Server/Plugin/helpers.py b/src/lib/Bcfg2/Server/Plugin/helpers.py
index 0b81077a3..93f690e18 100644
--- a/src/lib/Bcfg2/Server/Plugin/helpers.py
+++ b/src/lib/Bcfg2/Server/Plugin/helpers.py
@@ -1601,3 +1601,36 @@ class GroupSpool(Plugin, Generator):
return
reqid = self.core.fam.AddMonitor(name, self)
self.handles[reqid] = relative
+
+
+class DeepcopyMixin(object):
+ """ Mixin that adds a __deepcopy__() function that tries to do the
+ right thing by:
+
+ #. Creating a new object of the same type by calling the
+ constructor with the arguments returned by
+ :func:`Bcfg2.Server.Plugin.helpers.DeepcopyMixin._deepcopy_constructor_args`;
+ #. Individually copying each attribute of the original object that
+ a) is not magical (``__whatever__``); b) is not callable; c) is
+ not a property; and d) is not in
+ :attr:`Bcfg2.Server.Plugin.helpers.DeepcopyMixin._deepcopy_exclude`.
+ """
+
+ #: Exclude the named attributes from the copy.
+ _deepcopy_exclude = ["fam", "logger", "setup"]
+
+ def _deepcopy_constructor_args(self):
+ """ Get a tuple of arguments that will be passed to the
+ constructor of this class to create a base object before the
+ individual attributes are deepcopied. """
+ raise NotImplementedError
+
+ def __deepcopy__(self, memo):
+ rv = self.__class__(*self._deepcopy_constructor_args())
+ for attr in dir(self):
+ if (not callable(getattr(self, attr)) and
+ (not attr.startswith("__") or not attr.endswith("__")) and
+ attr not in self._deepcopy_exclude and
+ not isinstance(getattr(self.__class__, attr, None), property)):
+ setattr(rv, attr, copy.deepcopy(getattr(self, attr), memo))
+ return rv