[kernel] r11133 - people/waldi/dkt/lib/dkt/hooks/modules

Bastian Blank waldi at alioth.debian.org
Wed Apr 23 09:19:02 UTC 2008


Author: waldi
Date: Wed Apr 23 09:19:01 2008
New Revision: 11133

Log:
lib/dkt/hooks/modules/backward_kpkg_hook.py: Add.


Added:
   people/waldi/dkt/lib/dkt/hooks/modules/backward_kpkg_hook.py

Added: people/waldi/dkt/lib/dkt/hooks/modules/backward_kpkg_hook.py
==============================================================================
--- (empty file)
+++ people/waldi/dkt/lib/dkt/hooks/modules/backward_kpkg_hook.py	Wed Apr 23 09:19:01 2008
@@ -0,0 +1,52 @@
+import os, subprocess
+
+from dkt.hooks import default_registry, interfaces, register
+from dkt.itemconfig.interfaces import IItemImageConfig, IItemPackageConfig
+
+class Hook(object):
+    safe_path = '/usr/sbin', '/sbin', '/usr/bin', '/bin'
+
+    def _call(self, systemconfig, type, itemconfig, maintainer_args):
+        try:
+            config = IItemImageConfig(itemconfig)
+            file = config.file
+        except TypeError:
+            file = ''
+        version = IItemPackageConfig(itemconfig).version
+
+        hook = systemconfig.get('backward-compatibility', 'kpkg-%s-hook' % type, None)
+        if hook is None:
+            return
+
+        hook_filename = None
+
+        if not hook.startswith('/'):
+            for i in self.safe_path:
+                f = os.path.join(i, hook)
+                if os.access(f, os.X_OK):
+                    hook_filename = f
+                    break
+        else:
+            if os.access(hook, os.X_OK):
+                hook_filename = hook
+
+        if hook_filename is None:
+            raise RuntimeError("Can't find %s hook: %s" % (type, hook))
+        
+        ret = subprocess.call([hook_filename, version, file], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
+        if ret:
+            raise RuntimeError("Failed to run %s hook: %d" % (type, ret))
+
+    def image_preinst(self, systemconfig, itemconfig, maintainer_args):
+        return self._call(systemconfig, 'preinst', itemconfig, maintainer_args)
+
+    def image_postinst(self, systemconfig, itemconfig, maintainer_args):
+        return self._call(systemconfig, 'postinst', itemconfig, maintainer_args)
+
+    def image_prerm(self, systemconfig, itemconfig, maintainer_args):
+        return self._call(systemconfig, 'prerm', itemconfig, maintainer_args)
+
+    def image_postrm(self, systemconfig, itemconfig, maintainer_args):
+        return self._call(systemconfig, 'postrm', itemconfig, maintainer_args)
+
+register('backward-kpkg-hook', interfaces.IImageTask, Hook(), default_registry.PRIORITY_LAST)



More information about the Kernel-svn-changes mailing list