def _check_analyse_opt(opt): """ Perform manual checks on opt-sturcture """ LOG.debug("Checking Options.") # for label if opt.label is None: opt.label = "Amplitude Detuning for Beam {:d}".format(opt.beam) # check if cleaning is properly specified if (any([opt.tune_x, opt.tune_y, opt.tune_cut]) and any([opt.tune_x_min, opt.tune_x_max, opt.tune_y_min, opt.tune_y_max]) ): raise ParameterError("Choose either the method of cleaning BBQ" "with tunes and cut or with min and max values") for plane in PLANES: tune = "tune_{:s}".format(plane.lower()) if opt[tune]: if opt.tune_cut is None: raise ParameterError("Tune cut is needed for cleaning tune.") opt["{:s}_min".format(tune)] = opt[tune] - opt.tune_cut opt["{:s}_max".format(tune)] = opt[tune] + opt.tune_cut if bool(opt.fine_cut) != bool(opt.fine_window): raise ParameterError("To activate fine cleaning, both fine cut and fine window need" "to be specified") return opt
def _check_parameter(self): """ EntryPoint specific checks for parameter """ for param in self.parameter: arg_name = param.get("name", None) if arg_name is None: raise ParameterError("A Parameter needs a Name!") if param.get("nargs", None) == argparse.REMAINDER: raise ParameterError("Parameter '{:s}' is set as remainder.".format(arg_name) + "This method is really buggy, hence it is forbidden.") if param.get("flags", None) is None: raise ParameterError("Parameter '{:s}'".format(arg_name) + "does not have flags.")
def add_parameter(self, **kwargs): """ Add parameter """ name = kwargs.pop("name") if name in self: raise ParameterError("'{:s}' is already a parameter.".format(name)) else: self[name] = kwargs
def add_params_to_generic(parser, params): """ Adds entry-point style parameter to either ArgumentParser, DictParser or EntryPointArguments """ params = copy.deepcopy(params) if isinstance(params, dict): params = EntryPoint._dict2list_param(params) if isinstance(parser, EntryPointParameters): for param in params: parser.add_parameter(param) elif isinstance(parser, ArgumentParser): for param in params: param["dest"] = param.pop("name", None) flags = param.pop("flags", None) if flags is None: parser.add_argument(**param) else: if isinstance(flags, basestring): flags = [flags] parser.add_argument(*flags, **param) elif isinstance(parser, DictParser): for param in params: if "nargs" in param: if param["nargs"] != "?": param["subtype"] = param.get("type", None) param["type"] = list if isinstance(param["nargs"], str): param.pop("nargs") if "action" in param: if param["action"] in ("store_true", "store_false"): param["type"] = bool param["default"] = not param["action"][6] == "t" else: raise ParameterError( "Action '{:s}' not allowed in EntryPoint") param.pop("action") param.pop("flags", None) name = param.pop("name") parser.add_parameter(name, **param) else: raise TypeError("Parser not recognised.") return parser