def _convert_val(self, param_type, val): if param_type["type"] == "native": switch = { "str" : lambda x: str(x), "list" : lambda x: list(x), "tuple" : lambda x: tuple(x), "dict" : lambda x: dict(x), "int" : lambda x: int(x), "float" : lambda x: float(x), "unicode" : lambda x: unicode(x) } return switch[param_type["name"]](val) elif param_type["type"] == "fileset": val = FileSet(val) return val elif param_type["type"] == "component": # val should be like this: # { "class": "SpecificComponent", "params": {} } # # allow for inheritance by letting the json specify the # specific class that will be used component_cls = self._get_component_cls(val["class"]) component_args = self._convert_params(val["params"], component_cls) val = component_cls(parent_log = self._log, job = self) val.init(**component_args) return val
elif param_type["type"] == "fileset": val = FileSet(val) return val elif param_type["type"] == "component": # val should be like this: # { "class": "SpecificComponent", "params": {} } # # allow for inheritance by letting the json specify the # specific class that will be used component_cls = self._get_component_cls(val["class"]) component_args = self._convert_params(val["params"], component_cls) val = component_cls(parent_log=self._log, job=self) val.init(**component_args) return val def _get_param_types(self, cls): cls_name = cls.__name__ filename = inspect.getfile(cls) filename = filename.replace(".pyc", ".py") with open(filename, "r") as f: source = f.read() pyclass = None mod = ast.parse(source) for node in mod.body: if isinstance(node, ast.ClassDef): cls = PyClass(self._log, filename, node)