[elbe-devel] [PATCH v1 1/2] Add decorator for RPCAPTCache to register to base manager

dion at linutronix.de dion at linutronix.de
Tue May 28 14:43:08 CEST 2019


From: Olivier Dion <dion at linutronix.de>

This make more sens in my opinion than registering after the
definition of the class.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/rpcaptcache.py | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/elbepack/rpcaptcache.py b/elbepack/rpcaptcache.py
index d4f4a794..5f35d419 100644
--- a/elbepack/rpcaptcache.py
+++ b/elbepack/rpcaptcache.py
@@ -21,14 +21,25 @@ from elbepack.aptprogress import (ElbeAcquireProgress, ElbeInstallProgress,
                                   ElbeOpProgress)
 from elbepack.aptpkgutils import getalldeps, APTPackage
 
+class MyMan(BaseManager):
+
+    @staticmethod
+    def register(cls):
+        BaseManager.register(cls.typeid, cls)
+        return cls
+
+
 class InChRootObject(object):
     def __init__(self, rfs):
         self.rfs = rfs
         self.rfs.enter_chroot()
         self.finalizer = Finalize(self, self.rfs.leave_chroot, exitpriority=10)
 
-
+ at MyMan.register
 class RPCAPTCache(InChRootObject):
+
+    typeid = "RPCAPTCache"
+
     # pylint: disable=too-many-public-methods
     def __init__(
             self,
@@ -275,14 +286,6 @@ class RPCAPTCache(InChRootObject):
                                                unpack=False)
             return self.rfs.fname(rel_filename)
 
-
-class MyMan(BaseManager):
-    pass
-
-
-MyMan.register("RPCAPTCache", RPCAPTCache)
-
-
 def get_rpcaptcache(
         rfs,
         log,
-- 
2.11.0




More information about the elbe-devel mailing list