Beispiel #1
0
    def test(self):
        report = []
        #check id
        if not self.id:
            report.append(
                (ConfigurationError, " WfProcessConf.id is empty", self))
        # check context
        o = TryResolveName(self.context)
        if not o:
            report.append((ImportError, " for WfProcessConf.context", self))

        for s in self.states:
            iface, conf = ResolveConfiguration(s)
            if iface != IWfStateConf:
                report.append(
                    (ConfigurationError,
                     " for WfProcessConf.states (not a state configuration)",
                     self))

        for t in self.transitions:
            iface, conf = ResolveConfiguration(t)
            if iface != IWfTransitionConf:
                report.append((
                    ConfigurationError,
                    " for WfProcessConf.states (not a transition configuration)",
                    self))

        return report
Beispiel #2
0
 def _LoadTransitions(self, transistionConfs):
     # resolve transitions configurations and load objects
     if not transistionConfs:
         return []
     self.transitions = []
     for s in transistionConfs:
         iface, conf = ResolveConfiguration(s)
         if iface != IWfTransitionConf:
             raise ConfigurationError, "Not a transition configuration"
         self.transitions.append(self._GetObj(conf))
Beispiel #3
0
 def _LoadStates(self, stateConfs):
     # resolve state configurations and load state objects
     if not stateConfs:
         return []
     self.states = []
     for s in stateConfs:
         iface, conf = ResolveConfiguration(s)
         if iface != IWfStateConf:
             raise ConfigurationError, "Not a state configuration"
         self.states.append(self._GetObj(conf))
Beispiel #4
0
    def Register(self, comp, name=None):
        """
        Register an application or component. This is usually done in the pyramid
        app file. The registered component is automatically loaded and set up to work
        with url traversal.
        
        *comp* can be one of the following cases

        - AppConf object
        - AppConf string as python dotted name
        - python object. Requires *name* parameter or *comp.id* attribute
        
        *name* is used as the url path name to lookup the component.

        """
        log = logging.getLogger("portal")
        iface, conf = ResolveConfiguration(comp)
        if not conf and isinstance(comp, basestring):
            raise ConfigurationError, "Portal registration failure. No name given (%s)" % (str(comp))
        if isinstance(comp, basestring) or isinstance(comp, baseConf):
            # factory methods
            if IAppConf.providedBy(conf):
                comp = ClassFactory(conf)(conf)
            elif IModuleConf.providedBy(conf):
                comp = ClassFactory(conf)(conf)
            elif iface and iface.providedBy(comp):
                comp = ResolveName(conf.context)(conf)
            elif isinstance(comp, basestring):
                comp = ResolveName(conf.context)(conf)

        try:
            name = name or conf.id
        except AttributeError:
            pass
        if not name:
            raise ConfigurationError, "Portal registration failure. No name given (%s)" % (str(comp))

        log.debug("Portal.Register: %s %s", name, repr(conf))
        self.__dict__[name] = comp
        comp.__parent__ = self
        comp.__name__ = name
        self.components.append(name)
Beispiel #5
0
    def _RegisterConfViews(self, conf):
        """
        Register view configurations included as ``configuration.views`` in other 
        configuration classes like ObjectConf, RootConf and so on.
        """
        views = None
        try:
            views = conf.views
        except:
            pass
        if not views:
            return
        for v in views:

            if isinstance(v, basestring):
                iface, conf = ResolveConfiguration(v)
                if not conf:
                    raise ConfigurationError, str(v)
                v = conf

            self.Register(v)
Beispiel #6
0
    def _GetWfObj(self, name, contextObject):
        """
        creates the root object
        """
        wfConf = None
        if isinstance(name, basestring):
            wfConf = self.GetWorkflowConf(name, contextObject)
            if isinstance(wfConf, (list, tuple)):
                wfConf = wfConf[0]
        if not wfConf:
            iface, wfConf = ResolveConfiguration(name)
            if not wfConf:
                raise ImportError, "Workflow process not found. Please load the workflow by referencing the process id. (%s)" % (
                    str(name))

        wfTag = wfConf.context
        wfObj = GetClassRef(wfTag, self.reloadExtensions, True, None)
        wfObj = wfObj(wfConf, self)
        if not _IGlobal.providedBy(contextObject):
            wfObj.__parent__ = contextObject
        return wfObj
Beispiel #7
0
 def _GetToolObj(self, name, contextObject):
     """
     creates the tool object
     """
     if isinstance(name, basestring):
         conf = self.GetToolConf(name, contextObject)
         if isinstance(conf, (list, tuple)):
             conf = conf[0]
     else:
         conf = name
     if not conf:
         iface, conf = ResolveConfiguration(name)
         if not conf:
             raise ImportError, "Tool not found. Please load the tool by referencing the tool id. (%s)" % (
                 str(name))
     tag = conf.context
     toolObj = GetClassRef(tag, self.reloadExtensions, True, None)
     toolObj = toolObj(conf, self)
     if not _IGlobal.providedBy(contextObject):
         toolObj.__parent__ = contextObject
     return toolObj
Beispiel #8
0
    def Register(self, module, **kw):
        """
        Include a module or configuration to store in the registry.

        Handles configuration objects with the following interfaces:
        
        - IAppConf
        - IRootConf
        - IObjectConf
        - IViewModuleConf
        - IViewConf 
        - IToolConf
        - IModuleConf
        - IWidgetConf
        - IWfProcessConf
        
        Other modules are registered as utility with **kws as parameters.
        
        raises TypeError, ConfigurationError, ImportError
        """
        iface, conf = ResolveConfiguration(module)
        if not conf:
            self.log.debug('Register python module: %s', str(module))
            return self.registry.registerUtility(module, **kw)

        # test conf
        if self.debug:
            r = conf.test()
            if r:
                v = FormatConfTestFailure(r)
                self.log.warn('Configuration test failed:\r\n%s', v)
                #return False

        self.log.debug('Register module: %s %s', str(conf), str(iface))
        # register module views
        if iface not in (IViewModuleConf, IViewConf):
            self._RegisterConfViews(conf)

        # reset cached class value. makes testing easier
        try:
            del conf._c_class
        except:
            pass

        # register module itself
        if hasattr(conf, "unlock"):
            conf.unlock()

        # events
        if conf.get("events"):
            for e in conf.events:
                self.log.debug('Register Event: %s for %s', str(e.event),
                               str(e.callback))
                self.ListenEvent(e.event, e.callback)

        if iface == IRootConf:
            self.registry.registerUtility(conf,
                                          provided=IRootConf,
                                          name=conf.id)
            if conf.default or not self._defaultRoot:
                self._defaultRoot = conf.id
            return True
        elif iface == IObjectConf:
            self.registry.registerUtility(conf,
                                          provided=IObjectConf,
                                          name=conf.id)
            return True

        elif iface == IViewConf:
            self.registry.registerUtility(conf,
                                          provided=IViewConf,
                                          name=conf.id or str(uuid.uuid4()))
            return True
        elif iface == IViewModuleConf:
            self.registry.registerUtility(conf,
                                          provided=IViewModuleConf,
                                          name=conf.id)
            if conf.widgets:
                for w in conf.widgets:
                    self.Register(w)
            return True

        elif iface == IToolConf:
            if conf.apply:
                for i in conf.apply:
                    if i == None:
                        self.registry.registerAdapter(conf, (_IGlobal, ),
                                                      IToolConf,
                                                      name=conf.id)
                    else:
                        self.registry.registerAdapter(conf, (i, ),
                                                      IToolConf,
                                                      name=conf.id)
            else:
                self.registry.registerAdapter(conf, (_IGlobal, ),
                                              IToolConf,
                                              name=conf.id)
            if conf.modules:
                for m in conf.modules:
                    self.Register(m, **kw)
            return True

        elif iface == IAppConf:
            self.registry.registerUtility(conf, provided=IAppConf, name="IApp")
            if conf.modules:
                for m in conf.modules:
                    self.Register(m)
            self.configuration = conf
            return True

        elif iface == IDatabaseConf:
            self.registry.registerUtility(conf,
                                          provided=IDatabaseConf,
                                          name="IDatabase")
            self.dbConfiguration = conf
            return True

        elif iface == IModuleConf:
            # modules
            if conf.modules:
                for m in conf.modules:
                    self.Register(m, **kw)
            self.registry.registerUtility(conf,
                                          provided=IModuleConf,
                                          name=conf.id)
            return True

        elif iface == IWidgetConf:
            for i in conf.apply:
                self.registry.registerAdapter(conf, (i, ),
                                              conf.widgetType,
                                              name=conf.id)
            return True

        elif iface == IWfProcessConf:
            if conf.apply:
                for i in conf.apply:
                    self.registry.registerAdapter(conf, (i, ),
                                                  IWfProcessConf,
                                                  name=conf.id)
            else:
                self.registry.registerAdapter(conf, (_IGlobal, ),
                                              IWfProcessConf,
                                              name=conf.id)
            return True

        raise TypeError, "Unknown configuration interface type (%s)" % (
            str(conf))