def build_service(self, name): self.logger.debug("Build service: %s" % name) service_config = self.service_config[name] class_full_name = service_config.get("class") if class_full_name: module_name, class_name = parse_module_class(class_full_name) module = self.get_module(module_name) clazz = getattr(module, class_name) args = self.build_arguments(service_config.get("arguments", [])) try: obj = clazz(*args) except Exception, e: self.logger.error( "Error when create service: %s. Class: %s. Arguments: %s" % (name, class_full_name, args) ) raise e
) raise e elif "delegate" in service_config: delegate_obj_name, delegate_name = service_config.get("delegate") obj = self.get(delegate_obj_name) return getattr(obj, delegate_name) else: factory = service_config.get("factory") if not factory: raise Exception("No class/factory for service: %s. Provided config: %s" % (name, service_config)) factory_class_name, method_name = factory module_name, class_name = parse_module_class(factory_class_name) module = self.get_module(module_name) clazz = getattr(module, class_name) method = getattr(clazz, method_name) args = self.build_arguments(service_config.get("arguments", [])) obj = method(*args) calls = service_config.get("calls", []) for method_name, method_args in calls: method_args = self.build_arguments(method_args) method = getattr(obj, method_name) method(*method_args)