def __init__(self, cnt, settings, name, mandatory, arg_name):
		self.settings = settings
		self.name = str(name)
		mandatory = mandatory.capitalize()

		try:
			exec("self.mandatory = " + mandatory)
		except (NameError, SyntaxError):
			raise err.NotBoolean(cnt, mandatory)
		self.arg_name = str(arg_name)
		test(check.var_name(self.name), err.InvalidName, (cnt, self.name))
		test(check.var_name_is_reserved(self.name), err.ReservedVarName, (cnt, self.name))
		test(isinstance(self.mandatory, bool), err.NotBoolean, (cnt, self.mandatory))
		test(check.optarg_name(self.arg_name), err.InvalidArgName, (cnt, self.arg_name))
    def __init__(self, cnt, settings, name, mandatory, arg_name):
        self.settings = settings
        self.name = str(name)
        mandatory = mandatory.capitalize()

        try:
            exec("self.mandatory = " + mandatory)
        except (NameError, SyntaxError):
            raise err.NotBoolean(cnt, mandatory)
        self.arg_name = str(arg_name)
        test(check.var_name(self.name), err.InvalidName, (cnt, self.name))
        test(check.var_name_is_reserved(self.name), err.ReservedVarName,
             (cnt, self.name))
        test(isinstance(self.mandatory, bool), err.NotBoolean,
             (cnt, self.mandatory))
        test(check.optarg_name(self.arg_name), err.InvalidArgName,
             (cnt, self.arg_name))
Example #3
0
    def __init__(self, cnt, settings, name, arg_type, arg_name, arg_range,
                 default_arg, desc):
        self.settings = settings
        self.name = name
        self.short = ""
        self.force_noshort = False
        self.short_only = False
        self.arg_type = str(arg_type)
        self.is_array = False
        self.arg_name = str(arg_name)
        self.arg_range = str(arg_range)
        self.default_arg = str(default_arg)
        self.desc = str(desc)

        self.arg_range_compiled_regex = None
        self.open_boundary = [False, False]

        splitnamealt = str(name).split("|")
        test(
            len(splitnamealt) == 1 or len(splitnamealt) == 2,
            err.WrongSplitAltName, (cnt, name))

        self.name = splitnamealt[0]
        splitname = str(splitnamealt[0]).split(",")
        test(
            len(splitname) == 1 or len(splitname) == 2, err.WrongSplitName,
            (cnt, splitnamealt[0]))
        if len(splitname) > 1:
            self.name = splitname[0]
            self.short = splitname[1]
        elif len(self.name) == 1:
            self.short = self.name
            self.short_only = True

        test(check.var_name(self.name), err.InvalidName, (cnt, self.name))
        test(self.name != "help", err.ReservedOptName, (cnt, self.name))
        test(self.name != "version", err.ReservedOptName, (cnt, self.name))
        test(check.var_name_is_reserved(self.name), err.ReservedVarName,
             (cnt, self.name))

        test(
            check.optname_short(self.short)
            or check.directive_short(self.short), err.InvalidShortOpt,
            (cnt, self.short))
        self.short = check.is_empty_or_none(self.short)
        if self.short == "-":
            self.short = None
            self.force_noshort = True

        self.name_alt = None
        self.short_alt = ""
        self.force_noshort_alt = False
        self.short_only_alt = False
        if len(splitnamealt) == 2:
            self.name_alt = splitnamealt[1]
            splitname = str(splitnamealt[1]).split(",")
            test(
                len(splitname) == 1 or len(splitname) == 2, err.WrongSplitName,
                (cnt, splitnamealt[1]))
            if len(splitname) > 1:
                self.name_alt = splitname[0]
                self.short_alt = splitname[1]
            elif len(self.name_alt) == 1:
                self.short_alt = self.name_alt
                self.short_only_alt = True
            test(check.alt_opt_name(self.name_alt), err.InvalidName,
                 (cnt, self.name_alt))
            test(self.name_alt != "help", err.ReservedOptName,
                 (cnt, self.name_alt))
            test(self.name_alt != "version", err.ReservedOptName,
                 (cnt, self.name_alt))
            #test(check.var_name_is_reserved(self.name_alt), err.ReservedVarName, (cnt, self.name_alt))

            test(
                check.optname_short(self.short_alt)
                or check.directive_short(self.short_alt), err.InvalidShortOpt,
                (cnt, self.short_alt))
            if self.short_alt == "-":
                self.short_alt = None
                self.force_noshort_alt = True

        self.short_alt = check.is_empty_or_none(self.short_alt)

        self.arg_type = self.arg_type.upper()

        if self.arg_type in ["INT+", "FLOAT+", "STRING+"]:
            self.arg_type = self.arg_type[:-1]
            self.is_array = True

        if self.arg_type == "INT":
            self.parse_type_int(cnt)
        elif self.arg_type == "FLOAT":
            self.parse_type_float(cnt)
        elif self.arg_type == "STRING":
            self.parse_type_string(cnt)
        elif self.arg_type == "NONE" or self.arg_type == "":
            self.parse_type_flag(cnt)
        else:
            raise err.InvalidArgType(cnt, self.arg_type)

        self.opt_name = self.name.replace("_", "-")
        self.opt_name_alt = None
        if self.name_alt != None:
            self.opt_name_alt = self.name_alt.replace("_", "-")
	def __init__(self, cnt, settings, name, arg_type, arg_name, arg_range, default_arg, desc):
		self.settings = settings
		self.name = name
		self.short = ""
		self.force_noshort = False
		self.short_only = False
		self.arg_type = str(arg_type)
		self.is_array = False
		self.arg_name = str(arg_name)
		self.arg_range = str(arg_range)
		self.default_arg = str(default_arg)
		self.desc = str(desc)

		self.arg_range_compiled_regex = None
		self.open_boundary = [False, False]

		splitnamealt = str(name).split("|")
		test(len(splitnamealt) == 1 or len(splitnamealt) == 2, err.WrongSplitAltName, (cnt, name))

		self.name = splitnamealt[0]
		splitname = str(splitnamealt[0]).split(",")
		test(len(splitname) == 1 or len(splitname) == 2, err.WrongSplitName, (cnt, splitnamealt[0]))
		if len(splitname) > 1:
			self.name = splitname[0]
			self.short = splitname[1]
		elif len(self.name) == 1:
			self.short = self.name
			self.short_only = True

		test(check.var_name(self.name), err.InvalidName, (cnt, self.name))
		test(self.name != "help", err.ReservedOptName, (cnt, self.name))
		test(self.name != "version", err.ReservedOptName, (cnt, self.name))
		test(check.var_name_is_reserved(self.name), err.ReservedVarName, (cnt, self.name))

		test(check.optname_short(self.short) or check.directive_short(self.short), err.InvalidShortOpt, (cnt, self.short))
		self.short = check.is_empty_or_none(self.short)
		if self.short == "-":
			self.short = None
			self.force_noshort = True

		self.name_alt = None
		self.short_alt = ""
		self.force_noshort_alt = False
		self.short_only_alt = False
		if len(splitnamealt) == 2:
			self.name_alt = splitnamealt[1]
			splitname = str(splitnamealt[1]).split(",")
			test(len(splitname) == 1 or len(splitname) == 2, err.WrongSplitName, (cnt, splitnamealt[1]))
			if len(splitname) > 1:
				self.name_alt = splitname[0]
				self.short_alt = splitname[1]
			elif len(self.name_alt) == 1:
				self.short_alt = self.name_alt
				self.short_only_alt = True
			test(check.alt_opt_name(self.name_alt), err.InvalidName, (cnt, self.name_alt))
			test(self.name_alt != "help", err.ReservedOptName, (cnt, self.name_alt))
			test(self.name_alt != "version", err.ReservedOptName, (cnt, self.name_alt))
			#test(check.var_name_is_reserved(self.name_alt), err.ReservedVarName, (cnt, self.name_alt))

			test(check.optname_short(self.short_alt) or check.directive_short(self.short_alt), err.InvalidShortOpt, (cnt, self.short_alt))
			if self.short_alt == "-":
				self.short_alt = None
				self.force_noshort_alt = True

		self.short_alt = check.is_empty_or_none(self.short_alt)

		self.arg_type = self.arg_type.upper()

		if self.arg_type in ["INT+", "FLOAT+", "STRING+"]:
			self.arg_type = self.arg_type[:-1]
			self.is_array = True

		if self.arg_type == "INT":
			self.parse_type_int(cnt)
		elif self.arg_type == "FLOAT":
			self.parse_type_float(cnt)
		elif self.arg_type == "STRING":
			self.parse_type_string(cnt)
		elif self.arg_type == "NONE" or self.arg_type == "":
			self.parse_type_flag(cnt)
		else:
			raise err.InvalidArgType(cnt, self.arg_type)

		self.opt_name = self.name.replace("_","-")
		self.opt_name_alt = None
		if self.name_alt != None:
			self.opt_name_alt = self.name_alt.replace("_","-")