Explorar el Código

base: add PropertyHolder.clone_properties

Be compatible with core-admin
Marek Marczykowski-Górecki hace 7 años
padre
commit
e94bdca206
Se han modificado 1 ficheros con 17 adiciones y 0 borrados
  1. 17 0
      qubesadmin/base.py

+ 17 - 0
qubesadmin/base.py

@@ -154,6 +154,23 @@ class PropertyHolder(object):
         assert isinstance(is_default, bool)
         return is_default
 
+    def clone_properties(self, src, proplist=None):
+        '''Clone properties from other object.
+
+        :param PropertyHolder src: source object
+        :param list proplist: list of properties \
+            (:py:obj:`None` or omit for all properties)
+        '''
+
+        if proplist is None:
+            proplist = self.property_list()
+
+        for prop in proplist:
+            try:
+                setattr(self, prop, getattr(src, prop))
+            except AttributeError:
+                continue
+
     def __getattr__(self, item):
         # pylint: disable=too-many-return-statements
         if item.startswith('_'):