tools/site_compare/command_line.py
def ParseArguments(self):
    """Given a command line, parse and validate the arguments."""

    # reset all the arguments before we parse
    for arg in self.args:
      arg.present = False
      arg.value = None

    self.parse_errors = []

    # look for arguments remaining on the command line
    while len(self.cmdline.rargs):
      try:
        self.ParseNextArgument()
      except ParseError, e:
        self.parse_errors.append(e.args[0])

    # after all the arguments are parsed, check for problems
    for arg in self.args:
      if not arg.present and arg.required:
        self.parse_errors.append("'%s': required parameter was missing"
                                 % arg.names[0])

      if not arg.present and arg.default:
        arg.present = True
        arg.value = arg.default

      if arg.present:
        for mutex in arg.mutex:
          if mutex.present:
            self.parse_errors.append(
              "'%s', '%s': arguments are mutually exclusive" %
              (arg.argstr, mutex.argstr))

        for depend in arg.depends:
          if not depend.present:
            self.parse_errors.append("'%s': '%s' must be specified as well" %
                                     (arg.argstr, depend.names[0]))

    # check for required groups
    for group in self.required_groups:
      if not [arg for arg in group if arg.present]:
        self.parse_errors.append("%s: at least one must be present" %
                         (", ".join(["'%s'" % arg.names[-1] for arg in group])))

    # if we have any validators, invoke them
    if not self.parse_errors and self.validator:
      try:
        self.validator(self)
      except ParseError, e:
        self.parse_errors.append(e.args[0])
Given a command line, parse and validate the arguments.
Given a command line, parse and validate the arguments.
Given a command line parse and validate the arguments .
def ParseArguments(self):
    for arg in self.args:
      arg.present = False
      arg.value = None
    self.parse_errors = []
    while len(self.cmdline.rargs):
      try:
        self.ParseNextArgument()
      except ParseError, e:
        self.parse_errors.append(e.args[0])
    for arg in self.args:
      if not arg.present and arg.required:
        self.parse_errors.append("'%s': required parameter was missing"
                                 % arg.names[0])
      if not arg.present and arg.default:
        arg.present = True
        arg.value = arg.default
      if arg.present:
        for mutex in arg.mutex:
          if mutex.present:
            self.parse_errors.append(
              "'%s', '%s': arguments are mutually exclusive" %
              (arg.argstr, mutex.argstr))
        for depend in arg.depends:
          if not depend.present:
            self.parse_errors.append("'%s': '%s' must be specified as well" %
                                     (arg.argstr, depend.names[0]))
    for group in self.required_groups:
      if not [arg for arg in group if arg.present]:
        self.parse_errors.append("%s: at least one must be present" %
                         (", ".join(["'%s'" % arg.names[-1] for arg in group])))
    if not self.parse_errors and self.validator:
      try:
        self.validator(self)
      except ParseError, e:
        self.parse_errors.append(e.args[0])
def ParseArguments ( self ) : for arg in self . args : arg . present = False arg . value = None self . parse_errors = [ ] while len ( self . cmdline . rargs ) : try : self . ParseNextArgument ( ) except ParseError , e : self . parse_errors . append ( e . args [ 0 ] ) for arg in self . args : if not arg . present and arg . required : self . parse_errors . append ( "'%s': required parameter was missing" % arg . names [ 0 ] ) if not arg . present and arg . default : arg . present = True arg . value = arg . default if arg . present : for mutex in arg . mutex : if mutex . present : self . parse_errors . append ( "'%s', '%s': arguments are mutually exclusive" % ( arg . argstr , mutex . argstr ) ) for depend in arg . depends : if not depend . present : self . parse_errors . append ( "'%s': '%s' must be specified as well" % ( arg . argstr , depend . names [ 0 ] ) ) for group in self . required_groups : if not [ arg for arg in group if arg . present ] : self . parse_errors . append ( "%s: at least one must be present" % ( ", " . join ( [ "'%s'" % arg . names [ - 1 ] for arg in group ] ) ) ) if not self . parse_errors and self . validator : try : self . validator ( self ) except ParseError , e : self . parse_errors . append ( e . args [ 0 ] )
Given a command line, parse and validate the arguments.
Given a command line parse and validate the arguments .
"""Given a command line, parse and validate the arguments.""" # reset all the arguments before we parse # look for arguments remaining on the command line # after all the arguments are parsed, check for problems # check for required groups # if we have any validators, invoke them
self