Exemple #1
0
    def __init__(self, **kwargs):
        """
        The __init__ method does 2 things:
        * copies Requirements -- since Requirements are defined as class
            attributes, we need to copy the objects to avoid conflicts with
            multiple instances of the same class etc...
            The copied objects are stored under a Requirements object available
            through the 'req' attribute. This way you can optionally change the
            Requirements of an instantiated Recipe.
        * copies and instantiates Parameters -- Parameters are also class
            attributes so they need to be copied into a Parameters() object
            (accessible in the 'params' attribute).
            Next, the copied objects are loaded with values from kwargs
            and checked if mandatory Parameters have values.
        """
        self.matched = None
        self.req = _Requirements()
        self.params = Parameters()
        for attr in dir(self):
            val = getattr(self, attr)
            if isinstance(val, HostReq):
                setattr(self.req, attr, copy.deepcopy(val))
            elif isinstance(val, Param):
                setattr(self.params, attr, copy.deepcopy(val))

        for name, val in kwargs.items():
            try:
                param = getattr(self.params, name)
                param.val = val
            except:
                raise RecipeError("Unknown parameter {}".format(name))

        for name, param in self.params:
            if param.mandatory and not param.set:
                raise RecipeError("Parameter {} is mandatory".format(name))
Exemple #2
0
    def __init__(self, **kwargs):
        """
        The __init__ method does 2 things:
        * copies Requirements -- since Requirements are defined as class
            attributes, we need to copy the objects to avoid conflicts with
            multiple instances of the same class etc...
            The copied objects are stored under a Requirements object available
            through the 'req' attribute. This way you can optionally change the
            Requirements of an instantiated Recipe.
        * copies and instantiates Parameters -- Parameters are also class
            attributes so they need to be copied into a Parameters() object
            (accessible in the 'params' attribute).
            Next, the copied objects are loaded with values from kwargs
            and checked if mandatory Parameters have values.
        """
        self._ctl = None
        self.runs = []
        self.req = _Requirements()
        self.params = Parameters()

        attrs = {name: getattr(type(self), name) for name in dir(type(self))}

        params = ((name, val) for name, val in attrs.items()
                  if isinstance(val, Param))
        for name, val in params:
            if name in kwargs:
                param_val = kwargs.pop(name)
                param_val = val.type_check(param_val)
                setattr(self.params, name, param_val)
            else:
                try:
                    param_val = copy.deepcopy(val.default)
                    setattr(self.params, name, param_val)
                except AttributeError:
                    if val.mandatory:
                        raise RecipeError(
                            "Parameter {} is mandatory".format(name))

        reqs = ((name, val) for name, val in attrs.items()
                if isinstance(val, HostReq))
        for name, val in reqs:
            new_val = copy.deepcopy(val)
            new_val.reinit_with_params(self.params)
            setattr(self.req, name, new_val)

        if len(kwargs):
            for key in list(kwargs.keys()):
                raise RecipeError("Unknown parameter {}".format(key))