예제 #1
0
    def getParameterOption(self, values, cdef):
        for k, v in self.parameters.items():
            if not isInt(k) and indexOf(v, values) >= 0:
                return True
            elif indexOf(v, values) >= 0:
                return v

        return cdef
예제 #2
0
    def parse(self):
        parseOptions = True
        self.parsed = self.tokens.copy()

        token = None

        if len(self.parsed) != 0:
            token = self.parsed.pop(0)

        while token is not None:
            if parseOptions and token == '':
                self.parseArgument(token)
            elif parseOptions and token == '--':
                parseOptions = False
            elif parseOptions and indexOf('--', token) == 0:
                self.parseLongOption(token)
            elif parseOptions and '-' == token[0] and '-' != token:
                self.parseShortOption(token)
            else:
                self.parseArgument(token)

            try:
                token = self.parsed.pop(0)
            except:
                break
예제 #3
0
    def __init__(self, name, shortcut, mode, description, default=None):
        if indexOf('--', name) == 0:
            name = name[2:]

        if name is None:
            raise ValueError('An option name cannot be empty.')

        reg = re.compile(r'-')

        if shortcut is not None:
            if type(shortcut) == list:
                for short in shortcut:
                    short = re.sub(reg, '', short)  # weird

                shortcut = '|'.join(shortcut)
            else:
                shortcut = re.sub(reg, '', shortcut)

        if mode is None:
            mode = self.VALUE_NONE
        elif not int(mode) or mode > 15 or mode < 1:
            raise ValueError('Option mode {} is not valid.'.format(str(mode)))

        self.name = name
        self.shortcut = shortcut
        self.mode = mode
        self.description = description
        self.default = []

        if self.isArray() and not self.acceptValue():
            raise ValueError(
                'Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.'
            )

        self.setDefault(default)
예제 #4
0
    def hasParameterOption(self, values):

        for token in self.tokens:
            for value in values:
                if token == value or 0 == indexOf(value + '=', token):
                    return True

        return False
예제 #5
0
    def parseLongOption(self, token):
        name = token[2:]
        pos = indexOf('=', name)

        if pos >= 0:
            self.addLongOption(name[0:pos], name[pos + 1:])
        else:
            self.addLongOption(name, None)
예제 #6
0
 def parse(self):
     for key, value in self.parameters.items():
         if indexOf('--', key) >= 0:
             self.addLongOption(key[2:], value)
         elif '-' == key[0]:
             self.addShortOption(key[1:], value)
         else:
             self.addArgument(key, value)
예제 #7
0
    def hasParameterOption(self, values):
        for k, v in self.parameters.items():
            if not isInt(k):
                v = k

            if indexOf(v, values) >= 0:
                return True

        return False
예제 #8
0
	def askCombo(self, question, definition, choices, caseSensitive = False, fgColor='reset', bgColor='reset'):
		while True:
			inputValue = self.ask(question, definition, fgColor=fgColor, bgColor=bgColor)

			if indexOf(inputValue, choices) < 0:
				continue

			if not caseSensitive:
				inputValue = inputValue.lower()

			break

		return inputValue
예제 #9
0
    def getParameterOption(self, values, definition):

        tokens = self.tokens.copy()
        token = None

        if len(tokens) != 0:
            token = tokens.pop(0)

        while token:
            for value in values:
                if token == value or 0 == indexOf(value + '=', token):
                    pos = indexOf('=', token)

                    if False != pos:
                        return token[pos + 1:]

            # weird
            # if len(tokens) != 0:
            # 	token = tokens.pop(0)

            return tokens.pop(0)

        return definition