]> git.decadent.org.uk Git - dak.git/blobdiff - dak/dak.py
initial support for local python extensions
[dak.git] / dak / dak.py
index f82d74ccaafd18eb79361a78d8f2678f91f5eec1..10da0411b2a4e658e9141b07cd13fea9228ac383 100755 (executable)
 
 ################################################################################
 
-import sys
+import sys, imp
 import daklib.utils
 
 ################################################################################
 
+class UserExtension:
+    def __init__(self, user_extension = None):
+        if user_extension:
+           m = imp.load_source("dak_userext", user_extension)
+           d = m.__dict__
+        else:
+            m, d = None, {}
+       self.__dict__["_module"] = m
+       self.__dict__["_d"] = d
+
+    def __getattr__(self, a):
+        if a in self.__dict__: return self.__dict__[a]
+        if a[0] == "_": raise AttributeError, a
+        return self._d.get(a, None)
+
+    def __setattr__(self, a, v):
+       self._d[a] = v
+
+################################################################################
+
 def init():
     """Setup the list of modules and brief explanation of what they
     do."""
@@ -143,6 +163,13 @@ Availble commands:"""
 def main():
     """Launch dak functionality."""
 
+    Cnf = daklib.utils.get_conf()
+
+    if Cnf.has_key("Dinstall::UserExtensions"):
+        userext = UserExtension(Cnf["Dinstall::UserExtensions"])
+    else:
+        userext = UserExtension()
+
     functionality = init()
     modules = [ command for (command, _) in functionality ]
     
@@ -179,6 +206,11 @@ def main():
 
     # Invoke the module
     module = __import__(cmdname.replace("-","_"))
+
+    module.dak_userext = userext
+    userext.dak_module = module
+    if userext.init is not None: userext.init(cmdname)
+
     module.main()
 
 ################################################################################