[kernel] r9400 - in people/waldi/dkt/lib/dkt: config hooks hooks/modules

Bastian Blank waldi at alioth.debian.org
Tue Aug 28 20:51:22 UTC 2007


Author: waldi
Date: Tue Aug 28 20:51:22 2007
New Revision: 9400

Log:
lib/dkt: Update.


Added:
   people/waldi/dkt/lib/dkt/config/hooks.py
   people/waldi/dkt/lib/dkt/hooks/modules/__init__.py
   people/waldi/dkt/lib/dkt/hooks/modules/backward_boot.py
Modified:
   people/waldi/dkt/lib/dkt/config/interfaces.py
   people/waldi/dkt/lib/dkt/hooks/__init__.py
   people/waldi/dkt/lib/dkt/hooks/interfaces.py
   people/waldi/dkt/lib/dkt/hooks/registry.py

Added: people/waldi/dkt/lib/dkt/config/hooks.py
==============================================================================
--- (empty file)
+++ people/waldi/dkt/lib/dkt/config/hooks.py	Tue Aug 28 20:51:22 2007
@@ -0,0 +1,17 @@
+from dkt.hooks import default_registry, interfaces, register
+from dkt.interface import implements
+
+class Hook(object):
+    implements(interfaces.IImagePrepare)
+
+    def image_prepare(self, list):
+        pass
+
+class HookOverride(object):
+    implements(interfaces.IImagePrepare)
+
+    def image_prepare(self, list):
+        pass
+
+register("config", interfaces.IImagePrepare, Hook())
+register("config-override", interfaces.IImagePrepare, Hook(), default_registry.PRIORITY_LAST)

Modified: people/waldi/dkt/lib/dkt/config/interfaces.py
==============================================================================
--- people/waldi/dkt/lib/dkt/config/interfaces.py	(original)
+++ people/waldi/dkt/lib/dkt/config/interfaces.py	Tue Aug 28 20:51:22 2007
@@ -32,7 +32,3 @@
     def set(section, option, value):
         pass
 
-class IOrderedMutableConfig(IMutableConfig):
-    def append_section(section, data = {}):
-        pass
-

Modified: people/waldi/dkt/lib/dkt/hooks/__init__.py
==============================================================================
--- people/waldi/dkt/lib/dkt/hooks/__init__.py	(original)
+++ people/waldi/dkt/lib/dkt/hooks/__init__.py	Tue Aug 28 20:51:22 2007
@@ -2,3 +2,9 @@
 
 default_registry = registry.Registry()
 register = default_registry.register
+
+def load(path):
+    from load import load
+    load(__name__ + '.modules_user', path)
+
+import modules

Modified: people/waldi/dkt/lib/dkt/hooks/interfaces.py
==============================================================================
--- people/waldi/dkt/lib/dkt/hooks/interfaces.py	(original)
+++ people/waldi/dkt/lib/dkt/hooks/interfaces.py	Tue Aug 28 20:51:22 2007
@@ -14,7 +14,7 @@
     pass
 
 class IImagePrepare(IHookRunAllArg):
-    def image_prepare():
+    def image_prepare(list):
         pass
 
 class IImageTask(IHookRunAll):

Added: people/waldi/dkt/lib/dkt/hooks/modules/__init__.py
==============================================================================
--- (empty file)
+++ people/waldi/dkt/lib/dkt/hooks/modules/__init__.py	Tue Aug 28 20:51:22 2007
@@ -0,0 +1,6 @@
+def _load_default():
+    from dkt.hooks.load import load
+    for path in __path__:
+        load(__name__ + '.modules', path + '/modules')
+
+_load_default()

Added: people/waldi/dkt/lib/dkt/hooks/modules/backward_boot.py
==============================================================================
--- (empty file)
+++ people/waldi/dkt/lib/dkt/hooks/modules/backward_boot.py	Tue Aug 28 20:51:22 2007
@@ -0,0 +1,18 @@
+from dkt.hooks import default_registry, interfaces, register
+
+class Hook(object):
+    def _get_files(self):
+        ret = []
+        for root, dirs, files in os.walk('/boot'):
+            del dirs[:]
+            for file in files:
+                if file.startswith("vmlinuz-") or \
+                   file.startswith("vmlinux-") or \
+                   file.startswith("initrd.img-"):
+                    ret.append(file)
+        return ret
+
+    def image_prepare(self, list):
+        return list
+
+register('backward-boot', interfaces.IImagePrepare, Hook(), default_registry.PRIORITY_LAST, (), ('config-override',))

Modified: people/waldi/dkt/lib/dkt/hooks/registry.py
==============================================================================
--- people/waldi/dkt/lib/dkt/hooks/registry.py	(original)
+++ people/waldi/dkt/lib/dkt/hooks/registry.py	Tue Aug 28 20:51:22 2007
@@ -11,20 +11,30 @@
     def enable_module(self, module):
         pass
 
-    def register(self, module, interface, callable, priority = PRIORITY_MIDDLE, predecessors = (), successors = ()):
+    def register(self, module, interface, object, priority = PRIORITY_MIDDLE, predecessors = (), successors = ()):
         i = self._interfaces.get(interface, None)
         if i is None:
             i = HookList()
-        i.add(module, interface, callable, priority, predecessors, successors)
+        i.add(module, interface, object, priority, predecessors, successors)
         self._interfaces[interface] = i
 
     def run(self, interface, *args, **kw):
-        runner = interface._runner()
+        import interfaces, runner
+        if issubclass(interface, interfaces.IHookRunAll):
+            r = runner.RunAll
+        elif issubclass(interface, interfaces.IHookRunAllArg):
+            r = runner.RunAllArg
+        elif issubclass(interface, interfaces.IHookRunFirst):
+            r = runner.RunFirst
+        else:
+            raise RuntimeError
+        l = [i.object for i in self._interfaces[interface]._modules.itervalues()]
+        return r(l)
 
 class Hook(object):
-    def __init__(self, module, interface, callable, priority, predecessors, successors):
+    def __init__(self, module, interface, object, priority, predecessors, successors):
         self.module, self.interface = module, interface
-        self.callable, self.priority = callable, priority
+        self.object, self.priority = object, priority
         self.predecessors, self.successors = predecessors, successors
 
     def __repr__(self):
@@ -79,11 +89,11 @@
                 if not len(j.edge_in):
                     Q.append(j)
 
-        out.sort(lambda a, b: a.priority - b.priority)
+        out.sort(lambda a, b: cmp(a.priority, b.priority))
         return out
 
-    def add(self, module, interface, callable, priority, predecessors, successors):
-        self._modules[module] = Hook(module, interface, callable, priority, predecessors, successors)
+    def add(self, module, interface, object, priority, predecessors, successors):
+        self._modules[module] = Hook(module, interface, object, priority, predecessors, successors)
         self._sorted = None
 
     def get(self):



More information about the Kernel-svn-changes mailing list