def __call__(self, parser, namespace, values, option_string=None): self._checkValue(parser, namespace, values, option_string) items = argparse._copy.copy( argparse._ensure_value(namespace, 'statement', [])) items.append((self.ARGTYPE, values)) setattr(namespace, 'statement', items)
def __call__(self, parser, namespace, values, option_string=None): if not nmin<=len(values)<=nmax: msg='argument "{f}" requires between {nmin} and {nmax} arguments'.format(f=self.dest, nmin=nmin, nmax=nmax) raise argparse.ArgumentTypeError(msg) items = _ensure_value(namespace, self.dest, []) items.append(values) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = copy.copy(argparse._ensure_value(namespace, self.dest, {})) try: items.update(self.load_variables(values)) except ValueError as e: raise parser.error(option_string + ": " + e.message) setattr(namespace, self.dest, items)
def getprior(self, namespace): ''' Retrieves input from prior argument (e.g. pygby --max 8 --max 2 3) ''' from copy import copy prior = copy(argparse._ensure_value(namespace, self.dest, [])) return(prior)
def __call__(self, parser, namespace, values, option_string=None): items = copy.copy(argparse._ensure_value(namespace, self.dest, {})) try: items.update(self.load_variables(values)) except ValueError as exc: raise parser.error(option_string + ": " + str(exc)) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = argparse._copy.copy( argparse._ensure_value(namespace, self.dest, [])) ## the only one important line: for v in values: items.append(v) setattr(namespace, self.dest, items)
def getprior(self, namespace): ''' Retrieves input from prior argument (e.g. pygby --max 8 --max 2 3) ''' from copy import copy prior = copy(argparse._ensure_value(namespace, self.dest, [])) return (prior)
def __call__(self, parser, namespace, values, option_string=None): items = _copy.copy(argparse._ensure_value(namespace, self.dest, [])) if not self.nargs or self.nargs < 1: items.extend(filter(None, values.split(','))) else: for value in values: items.extend(filter(None, value.split(','))) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): if values is None: values = [] elif not isinstance(values, list): values = [values] items = argparse._ensure_value(namespace, self.dest, [])[:] items.append([self.const] + values) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = copy.copy(argparse._ensure_value(namespace, self.dest, [])) valid_items = [] for value in values.split(","): # Do validation. valid_items.append(value) items += valid_items setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = argparse._copy.copy(argparse._ensure_value(namespace, self.dest, [])) try: self._not_first except AttributeError: self._not_first = True del items[:] items.append(values) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): if not os.path.isdir(values): message = "No such directory: %r for option %r, aborting..." message = message % (values, option_string) logger.critical(message) raise ValueError(message) items = _copy.copy(argparse._ensure_value(namespace, self.dest, [])) items.append(values) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): try: k, v = values.split("=", 1) except ValueError: raise argparse.ArgumentError(self, "Format must be key=value") items = copy.copy(argparse._ensure_value(namespace, self.dest, {})) items[k] = v setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = argparse._copy.copy( argparse._ensure_value(namespace, self.dest, []) ) try: items.remove(self.const) except ValueError: pass else: setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): try: k, v = values.split("=", 1) except ValueError: raise argparse.ArgumentError(self, "Format must be key=value") # Implementation is from argparse._AppendAction items = copy.copy(argparse._ensure_value( namespace, self.dest, {})) # Default mutables, use copy! items[k] = v setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = copy.copy(_ensure_value(namespace, self.dest, {})) 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)
def __call__(self, parser, namespace, values, option_string): items = copy.copy(_ensure_value(namespace, self.dest, [])) try: items.extend(values) except TypeError: # Assume the TypeError is because values is not iterable raise ArgumentTypeError( "argument type '{:s}' is not iterable".format( type(values).__name__)) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): if isinstance(values, dict): # Get the existing arg value (if any) items = copy.copy(argparse._ensure_value(namespace, self.dest, {})) # Merge the new key/value pair(s) in for k, v in values.iteritems(): if k in items: v = self.onduplicatekey_handler(self, k, items[k], v) items[k] = v else: # Get the existing arg value (if any) items = copy.copy(argparse._ensure_value(namespace, self.dest, [])) # Merge the new key/value pair(s) in for k in values: if k in items: self.onduplicatekey_handler(self, k) else: items.append(k) # Saved the merged dictionary setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): new_count = argparse._ensure_value(namespace, self.dest, 0) + 1 setattr(namespace, self.dest, new_count) _log = logging.getLogger() # root logger! level = min(logging.CRITICAL, _log.level + logging.DEBUG) if _log.level != level: log.debug("Changing logging level: %s -> %s", logging.getLevelName(_log.level), logging.getLevelName(level)) _log.setLevel(level) log.debug("New logging level: %s", logging.getLevelName(_log.level))
def __call__(self, parser, namespace, values, option_string=None): print type(values) items = copy.copy(argparse._ensure_value(namespace, self.dest, [])) items = [os.path.abspath(os.path.expanduser(item)) for item in items] valid_filenames = [] # Split commas and do not paths that are not valid. for value in values.split(","): # Do validation. path_to_filename = os.path.abspath(os.path.expanduser(value)) if (os.path.exists(path_to_filename) and os.path.isfile(path_to_filename)): valid_filenames.append(path_to_filename) items += valid_filenames setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = copy.copy(argparse._ensure_value(namespace, self.dest, [])) items = [os.path.abspath(os.path.expanduser(item)) for item in items] valid_filenames = [] for value in values: if (os.path.exists(os.path.abspath(os.path.expanduser(value))) and os.path.isfile(os.path.abspath(os.path.expanduser(value)))): valid_filenames.append(os.path.abspath(os.path.expanduser(value))) elif (os.path.exists(os.path.abspath(os.path.expanduser(value))) and os.path.isdir(os.path.abspath(os.path.expanduser(value)))): for path_to_filename in glob.glob("%s/*" %(value.rstrip("/"))): valid_filenames.append(os.path.abspath(os.path.expanduser(path_to_filename))) items += valid_filenames # Remove duplicates before setting. setattr(namespace, self.dest, dict.fromkeys(items).keys())
def __call__(self, parser, namespace, values, option_string=None): """ Internal method of argparse.Action This method is invoked to "apply" the action after seeing all the values for a given argument. Please refer to argparse source code for information on how it is used. """ items = copy.copy(argparse._ensure_value(namespace, self.dest, {})) for value in values: try: k, v = value.split("=", 1) except ValueError: raise argparse.ArgumentError(self, "expected NAME=VALUE") else: items[k] = v setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): """ Internal method of argparse.Action This method is invoked to "apply" the action after seeing all the values for a given argument. Please refer to argparse source code for information on how it is used. """ items = copy.copy(argparse._ensure_value(namespace, self.dest, {})) for value in values: try: k, v = value.split('=', 1) except ValueError: raise argparse.ArgumentError(self, "expected NAME=VALUE") else: items[k] = v setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): new_count = argparse._ensure_value(namespace, self.dest, 0) + 1 setattr(namespace, self.dest, new_count) start_dry_run_mode() # increase
def __call__(self, parser, namespace, values, option_string=None): warn_deprecated_opt(option_string) items = argparse._copy.copy( argparse._ensure_value(namespace, self.dest, [])) items.append(values) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = _copy.copy(argparse._ensure_value(namespace, self.dest, {})) items[values[0]] = values[1] setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): """Parse out space-separated list of nodes.""" items = argparse._copy.copy(argparse._ensure_value(namespace, self.dest, [])) items.extend([value.strip() for value in values.split()]) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = argparse._copy.copy( argparse._ensure_value(namespace, self.dest, [])) items.append(upload_command(open(values[0], 'rb'), values[1])) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = _copy.copy(_ensure_value(namespace, self.dest, [])) items.append(self.subparser.parse_args(values)) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): items = copy.copy(argparse._ensure_value(namespace, self.dest, {})) for kv in values.split(','): k, v = kv.split('=') items[k] = _strtovalue(v) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): """Parse out space-separated list of nodes.""" items = argparse._copy.copy( argparse._ensure_value(namespace, self.dest, [])) items.extend([value.strip() for value in values.split()]) setattr(namespace, self.dest, items)
def __call__(self, parser, namespace, values, option_string=None): new_value = not argparse._ensure_value(namespace, self.dest, False) setattr(namespace, self.dest, new_value)
def __call__(self, parser, namespace, values, option_string=None): new_count = argparse._ensure_value(namespace, self.dest, 0) if option_string != '-q': new_count += 1 setattr(namespace, self.dest, new_count)
def __call__(self, parser, namespace, values, option_string=None): items = copy.copy(argparse._ensure_value(namespace, self.dest, {})) items.update(self.load_variables(values)) setattr(namespace, self.dest, items)