示例#1
0
    def register(self, doc=None):
        def fn(cls):
            return super(ModelComponentFactoryClass,
                         self).register(cls.__name__, doc)(cls)

        return fn


ModelComponentFactory = ModelComponentFactoryClass('model component')


class IParamRepresentation(Interface):
    pass


ParamRepresentationFactory = CreatePluginFactory(IParamRepresentation)


class TransformationInfo(object):
    pass


class TransformationData(object):
    """
    This is a container class that supports named data objects.
    """
    def __init__(self):
        self._data = {}

    def __getitem__(self, name):
        if not name in self._data:
示例#2
0
文件: plugin.py 项目: conradbm/pyomo
def ExpressionFactory(name=None, args=[]):
    ep = ExpressionFactory.ep
    if name is None:
        return map(lambda x: x.name, ep())
    return ep.service(name).create(args)


ExpressionFactory.ep = ExtensionPoint(IPyomoExpression)


class IModelComponent(Interface):
    pass


ModelComponentFactory = CreatePluginFactory(IModelComponent)


def register_component(cls, description):
    class TMP(Plugin):
        implements(IModelComponent, service=False)
        alias(cls.__name__, description)
        component = cls


class IDataManager(Interface):
    def available(self):
        """ Returns True if the data manager can be executed """
        pass

    def requirements(self):
示例#3
0
文件: factory.py 项目: xfLee/pyomo
    def __init__(self, *args, **kwds):
        Plugin.__init__(self, **kwds)
        #
        # The 'type' is the class type of the solver instance
        #
        self.type = kwds["type"]

    def available(self):
        return False


#
# A DataManagerFactory is an instance of a plugin factory that is
# customized with a custom __call__ method
#
DataManagerFactory = CreatePluginFactory(IDataManager)


#
# This is the custom __call__ method
#
def __datamanager_call__(self, _name=None, args=[], **kwds):
    if _name is None:
        return self
    _name = str(_name)
    if _name in IDataManager._factory_active:
        dm = PluginFactory(IDataManager._factory_cls[_name], args, **kwds)
        if not dm.available():
            raise PluginError(
                "Cannot process data in %s files.  The following python packages need to be installed: %s"
                % (_name, dm.requirements()))