From 44b3addc25b3b07b0ed87d78c16f2c6912b71fc1 Mon Sep 17 00:00:00 2001 From: Jan Rusnacko Date: Wed, 30 Oct 2013 16:08:23 +0100 Subject: [PATCH 4/4] Cleaning DSModuleProxy from ds_instance. --- lib389/ds_instance.py | 85 +++++-------------------------------------------- 1 files changed, 8 insertions(+), 77 deletions(-) diff --git a/lib389/ds_instance.py b/lib389/ds_instance.py index 7545eee..6b7f71d 100644 --- a/lib389/ds_instance.py +++ b/lib389/ds_instance.py @@ -1,82 +1,13 @@ -import os, re, sys -class DSDecorator(object): - """ Implements decorator that can be instantiated during runtime. - - Accepts function and instance of DSInstance. When called, - it will call passed function with instance of DSInstance - passed as the first argument. - """ - def __init__(self, fun, ds_instance): - self.fun = fun - self.ds_instance = ds_instance - - def __call__(self, *args, **kwargs): - if args is None and kwargs is None: - return self.fun(self.ds_instance) - elif args is not None and kwargs is None: - return self.fun(self.ds_instance, *args) - elif args is None and kwargs is not None: - return self.fun(self.ds_instance, **kwargs) - else: - return self.fun(self.ds_instance, *args, **kwargs) - -class DSModuleProxy(object): - """ Proxy with DS-decorated functions from modules in directory. - - DSModuleProxy object acts as a proxy to functions defined in modules - stored in directory. Proxy itself can have other proxies as - attributes, so returned object follows the structure of passed - directory. All funcions from all modules are decorated with - DSDecorator - DSInstance object will be passed to them as first - argument. - - Kudos to Milan Falesnik - """ - - def __init__(self, module_name): - self.name = module_name - - @classmethod - def populate_with_proxies(cls, ds, obj, directory): - """ - Returns a proxy with decorated functions from modules in directory. - """ - if not os.path.isdir(directory): - raise RuntimeError("Last argument %s was not directory" % directory) - for item in os.listdir(directory): - - # case when item is directory - if os.path.isdir(directory + "/" + item): - # Recursively call self on all subdirectories - proxy = cls(item) - cls.populate_with_proxies(ds, proxy, directory + "/" + item) - setattr(obj, item, proxy) - - # case when item is python module - elif (os.path.isfile(directory + "/" + item) and - re.match(r'(.*\/)?[^_/].*[^_/]\.py$', item)): - - # get the module object corresponding to processed file - item = item.replace('.py', '') - to_import = (directory + "/" + item).replace('/','.') - __import__(to_import) - module = sys.modules[to_import] - proxy = cls(item) - - # for each function from module create decorated one and keep it - for attr in dir(module): - fun = getattr(module, attr) - if callable(fun): - decorated = DSDecorator(fun, ds) - setattr(proxy, attr, decorated) - setattr(obj, item, proxy) - - else: - # skip anything that is not directory or python module - pass +from lib389.module_proxy import DSModuleProxy class DSInstance(object): def __init__(self): - DSModuleProxy.populate_with_proxies(self, self, 'dsmodules') + DSModuleProxy.populate_with_proxies(self, self, "lib389/dsmodules") + + def ldapadd_r(self, input): + raise NotImplementedError + + def ldapdelete_r(self, dn): + raise NotImplementedError -- 1.7.1