def __call__(self,
                 parser,
                 namespace,
                 values,
                 option_string=None,
                 nargs='*'):
        # add each command line argument to the variable specfied as dest in the argparser call
        for arg in values:
            # get the current contents of the variable with the name stored in dest
            items = getattr(namespace, self.dest, None)
            # change items into a list containing the variables
            items = argparse._copy_items(items)
            # use the list method append to add the new argument to the list
            items.append(arg)
            # set the contents of the the variable with the name stored in dest to the new list
            setattr(namespace, self.dest, items)

        # repeat the actions done above with the variable with the name stored in perf
        # get current contents
        perform = getattr(namespace, self.perf, None)
        # change to a list
        perform = argparse._copy_items(perform)
        # add new argument
        perform.append(self.const)
        # set the variable
        setattr(namespace, self.perf, perform)
Пример #2
0
Файл: cli.py Проект: lmmx/mvdef
 def __call__(self, parser, namespace, values, option_string=None):
     mv_items = getattr(namespace, self.dest, None)
     mv_items = argparse._copy_items(mv_items)
     mv_items.append(values)
     setattr(namespace, self.dest, mv_items)
     # Append a `None` to the list for the `into` dest of the parser namespace
     paired_items = getattr(namespace, self.paired_dest, None)
     paired_items = argparse._copy_items(paired_items)
     paired_items.append(None)
     setattr(namespace, self.paired_dest, paired_items)
Пример #3
0
 def __call__(self, parser, namespace, values, option_string=None):
     # Python2 way
     # items = copy.copy(argparse._ensure_value(namespace, self.dest, []))
     items = getattr(namespace, self.dest, None)
     items = argparse._copy_items(items)
     # items = [clean_path(item) for item in items]
     items.append(clean_path(values))
     setattr(namespace, self.dest, items)
Пример #4
0
 def __call__(self, parser, namespace, values, option_string=None):
     addr, port = values.split(':')
     values = (addr, int(port))
     items = getattr(namespace, self.dest, None)
     if items == [('127.0.0.1', 65000)]:
         items = []
     else:
         items = argparse._copy_items(items)
     items.append(values)
     setattr(namespace, self.dest, items)
Пример #5
0
Файл: cli.py Проект: lmmx/mvdef
 def __call__(self, parser, namespace, values, option_string=None):
     items = getattr(namespace, self.dest, None)
     items = argparse._copy_items(items)
     if items:
         items.pop()  # remove the last `None` appended by _MvAction
     else:
         raise argparse.ArgumentError(
             None,
             f"Cannot set '{option_string}={values}', "
             "as no function was given to apply it to "
             f"({option_string} was called before -m/--mv)",
         )
     items.append(values)
     setattr(namespace, self.dest, items)
Пример #6
0
    def __call__(self, parser, namespace, values, option_string=None):
        items = getattr(namespace, self.dest, None)
        items = argparse._copy_items(items)

        if len(values) < 1:
            raise ValueError(f'TK: statement must contain at least 1 argument')

        # if len(values) == 1:
        #     newvals = [None] + values
        # else:
        #     newvals = values

        df = {
            'bool_type': None,
            'columns': None,
            'operator': None,
            'operand': None,
            'datatype': None,
            'extra_args': []
        }
        df['bool_type'] = self.option_strings[1].lstrip('-').upper()

        for i, val in enumerate(values):
            valobj = parse_value_type_arg(val)
            if valobj:
                if i >= 1:
                    df['columns'] = values[i - 1]
                df.update(valobj)
                df['extra_args'] = values[i + 1:]
                break
            else:
                pass

        # if len(values) == 1:
        #     valobj = parse_value_type_arg(values[0])
        # else:

        #     raise ValueError(f'TK: value arg for last statement seems to be invalid: {values[-1]}')
        # else:

        #     # then we assume no columns is specified, just a value_datatype str
        #     d['operand'], d['datatype'] = parse_value_type_arg(values[0])
        # if

        # newvals = [ctype] + values

        items.append(df)
        setattr(namespace, self.dest, items)
Пример #7
0
    def __call__(self, parser, namespace, values, option_string=None):
        items = getattr(namespace, self.dest, None)
        items = _copy_items(items)

        try:
            key, value = values.split(':')
        except ValueError:
            raise ArgumentError(self, 'key:value syntax not followed')

        key = key.strip()
        value = value.strip()

        if not key or not value:
            raise ArgumentError(self, 'key or value are empty')

        items.update({key: value})
        setattr(namespace, self.dest, items)
Пример #8
0
 def update_event(self, inp=-1):
     self.set_output_val(0, argparse._copy_items(self.input(0)))