tools/site_compare/command_line.py
def ParseNextArgument(self):
    """Find the next argument in the command line and parse it."""
    arg = None
    value = None
    argstr = self.cmdline.rargs.pop(0)

    # First check: is this a literal argument?
    if argstr.lower() in self.arg_dict:
      arg = self.arg_dict[argstr.lower()]
      if arg.type in Command.Argument.TYPES_WITH_VALUES:
        if len(self.cmdline.rargs):
          value = self.cmdline.rargs.pop(0)

    # Second check: is this of the form "arg=val" or "arg:val"?
    if arg is None:
      delimiter_pos = -1

      for delimiter in [':', '=']:
        pos = argstr.find(delimiter)
        if pos >= 0:
          if delimiter_pos < 0 or pos < delimiter_pos:
            delimiter_pos = pos

      if delimiter_pos >= 0:
        testarg = argstr[:delimiter_pos]
        testval = argstr[delimiter_pos+1:]

        if testarg.lower() in self.arg_dict:
          arg = self.arg_dict[testarg.lower()]
          argstr = testarg
          value = testval

    # Third check: does this begin an argument?
    if arg is None:
      for key in self.arg_dict.iterkeys():
        if (len(key) < len(argstr) and
            self.arg_dict[key].type in Command.Argument.TYPES_WITH_VALUES and
            argstr[:len(key)].lower() == key):
          value = argstr[len(key):]
          argstr = argstr[:len(key)]
          arg = self.arg_dict[argstr]

    # Fourth check: do we have any positional arguments available?
    if arg is None:
      for positional_arg in [
          testarg for testarg in self.args if testarg.positional]:
        if not positional_arg.present:
          arg = positional_arg
          value = argstr
          argstr = positional_arg.names[0]
          break

    # Push the retrieved argument/value onto the largs stack
    if argstr: self.cmdline.largs.append(argstr)
    if value:  self.cmdline.largs.append(value)

    # If we've made it this far and haven't found an arg, give up
    if arg is None:
      raise ParseError("Unknown argument: '%s'" % argstr)

    # Convert the value, if necessary
    if arg.type in Command.Argument.TYPES_WITH_VALUES and value is None:
      raise ParseError("Argument '%s' requires a value" % argstr)

    if value is not None:
      value = self.StringToValue(value, arg.type, argstr)

    arg.argstr = argstr
    arg.value = value
    arg.present = True

    # end method ParseNextArgument
Find the next argument in the command line and parse it.
Find the next argument in the command line and parse it.
Find the next argument in the command line and parse it .
def ParseNextArgument(self):
    arg = None
    value = None
    argstr = self.cmdline.rargs.pop(0)
    if argstr.lower() in self.arg_dict:
      arg = self.arg_dict[argstr.lower()]
      if arg.type in Command.Argument.TYPES_WITH_VALUES:
        if len(self.cmdline.rargs):
          value = self.cmdline.rargs.pop(0)
    if arg is None:
      delimiter_pos = -1
      for delimiter in [':', '=']:
        pos = argstr.find(delimiter)
        if pos >= 0:
          if delimiter_pos < 0 or pos < delimiter_pos:
            delimiter_pos = pos
      if delimiter_pos >= 0:
        testarg = argstr[:delimiter_pos]
        testval = argstr[delimiter_pos+1:]
        if testarg.lower() in self.arg_dict:
          arg = self.arg_dict[testarg.lower()]
          argstr = testarg
          value = testval
    if arg is None:
      for key in self.arg_dict.iterkeys():
        if (len(key) < len(argstr) and
            self.arg_dict[key].type in Command.Argument.TYPES_WITH_VALUES and
            argstr[:len(key)].lower() == key):
          value = argstr[len(key):]
          argstr = argstr[:len(key)]
          arg = self.arg_dict[argstr]
    if arg is None:
      for positional_arg in [
          testarg for testarg in self.args if testarg.positional]:
        if not positional_arg.present:
          arg = positional_arg
          value = argstr
          argstr = positional_arg.names[0]
          break
    if argstr: self.cmdline.largs.append(argstr)
    if value:  self.cmdline.largs.append(value)
    if arg is None:
      raise ParseError("Unknown argument: '%s'" % argstr)
    if arg.type in Command.Argument.TYPES_WITH_VALUES and value is None:
      raise ParseError("Argument '%s' requires a value" % argstr)
    if value is not None:
      value = self.StringToValue(value, arg.type, argstr)
    arg.argstr = argstr
    arg.value = value
    arg.present = True
def ParseNextArgument ( self ) : arg = None value = None argstr = self . cmdline . rargs . pop ( 0 ) if argstr . lower ( ) in self . arg_dict : arg = self . arg_dict [ argstr . lower ( ) ] if arg . type in Command . Argument . TYPES_WITH_VALUES : if len ( self . cmdline . rargs ) : value = self . cmdline . rargs . pop ( 0 ) if arg is None : delimiter_pos = - 1 for delimiter in [ ':' , '=' ] : pos = argstr . find ( delimiter ) if pos >= 0 : if delimiter_pos < 0 or pos < delimiter_pos : delimiter_pos = pos if delimiter_pos >= 0 : testarg = argstr [ : delimiter_pos ] testval = argstr [ delimiter_pos + 1 : ] if testarg . lower ( ) in self . arg_dict : arg = self . arg_dict [ testarg . lower ( ) ] argstr = testarg value = testval if arg is None : for key in self . arg_dict . iterkeys ( ) : if ( len ( key ) < len ( argstr ) and self . arg_dict [ key ] . type in Command . Argument . TYPES_WITH_VALUES and argstr [ : len ( key ) ] . lower ( ) == key ) : value = argstr [ len ( key ) : ] argstr = argstr [ : len ( key ) ] arg = self . arg_dict [ argstr ] if arg is None : for positional_arg in [ testarg for testarg in self . args if testarg . positional ] : if not positional_arg . present : arg = positional_arg value = argstr argstr = positional_arg . names [ 0 ] break if argstr : self . cmdline . largs . append ( argstr ) if value : self . cmdline . largs . append ( value ) if arg is None : raise ParseError ( "Unknown argument: '%s'" % argstr ) if arg . type in Command . Argument . TYPES_WITH_VALUES and value is None : raise ParseError ( "Argument '%s' requires a value" % argstr ) if value is not None : value = self . StringToValue ( value , arg . type , argstr ) arg . argstr = argstr arg . value = value arg . present = True
Find the next argument in the command line and parse it.
Find the next argument in the command line and parse it .
"""Find the next argument in the command line and parse it.""" # First check: is this a literal argument? # Second check: is this of the form "arg=val" or "arg:val"? # Third check: does this begin an argument? # Fourth check: do we have any positional arguments available? # Push the retrieved argument/value onto the largs stack # If we've made it this far and haven't found an arg, give up # Convert the value, if necessary # end method ParseNextArgument
self