Example #1
0
def _parse_args():
    parser = argparse.ArgumentParser(prog=__progname__,
                                     description=__description__,
                                     version=__version__,
                                     conflict_handler='resolve')
    commands = ICommand.implementors()
    for command in commands:
        name = command.command_name()
        option_group = parser.add_argument_group(
            description="Options added by the {0} subcommand".format(name))
        # Add the custom command aditional options
        for opt in command.extra_options():
            option_group.add_argument(opt.name,
                                      help=opt.help,
                                      dest=opt.dest,
                                      action=opt.action,
                                      default=opt.default_value)

    # Add wsgid core options
    for opt in _create_core_options():
        if opt.type is bool:
            # We cannot pass type= when action is 'store_true', go figure!
            parser.add_argument(opt.name,
                                help=opt.help,
                                dest=opt.dest,
                                action=opt.action,
                                default=opt.default_value)
        else:
            parser.add_argument(opt.name,
                                help=opt.help,
                                type=opt.type,
                                dest=opt.dest,
                                action=opt.action,
                                default=opt.default_value)
    return parser.parse_args()
Example #2
0
def run_command():
  command_implementors = ICommand.implementors()
  if command_implementors and len(sys.argv) > 1:
    cname = sys.argv[1] # get the command name
    for command in command_implementors:
      if command.name_matches(cname):
        # Remove the command name, since it's not defined
        # in the parser options
        sys.argv.remove(cname)
        command.run(parser.parse_options(use_config = False))
        return True
  return False
Example #3
0
def run_command():
    command_implementors = ICommand.implementors()
    if command_implementors and len(sys.argv) > 1:
        cname = sys.argv[1]  # get the command name
        for command in command_implementors:
            if command.name_matches(cname):
                # Remove the command name, since it's not defined
                # in the parser options
                sys.argv.remove(cname)
                command.run(parser.parse_options(use_config=False))
                return True
    return False
Example #4
0
def run_command():
    '''
    Extract the first command line argument (if it exists)
    and tries to find a ICommand implementor for it.
    If found, run it. If not does nothing.
    '''
    command_implementors = ICommand.implementors()
    if command_implementors and len(sys.argv) > 1:
        cname = sys.argv[1]  # get the command name
        for command in command_implementors:
            if command.name_matches(cname):
                # Remove the command name, since it's not defined
                # in the parser options
                sys.argv.remove(cname)
                command.run(parser.parse_options(use_config=False), command_name=cname)
                return True
    return False
Example #5
0
def _create_optparse(prog, description, version):
    import optparse
    optparser = optparse.OptionParser(prog=prog, description=description, version=version)
    commands = ICommand.implementors()
    for command in commands:
      name = command.command_name()
      option_group = optparse.OptionGroup(optparser, "Options added by the {0} subcommand".format(name))
      
      # Add the custom command aditional options
      for opt in command.extra_options():
        option_group.add_option(opt.name, help = opt.help, dest = opt.dest, action = opt.action, default = opt.default_value)

    for opt in _create_core_options():
      optparser.add_option(opt.name, help = opt.help, \
                           type = opt.type, action = opt.action, \
                           dest = opt.dest, default = opt.default_value)
    return optparser
Example #6
0
def _parse_args():
  parser = argparse.ArgumentParser(prog=__progname__, description=__description__, version=__version__, conflict_handler='resolve' )
  commands = ICommand.implementors()
  for command in commands:
    name = command.command_name()
    option_group = parser.add_argument_group(description="Options added by the {0} subcommand".format(name))
    # Add the custom command aditional options
    for opt in command.extra_options():
      option_group.add_argument(opt.name, help = opt.help, dest = opt.dest, action = opt.action, default = opt.default_value)

  # Add wsgid core options
  for opt in _create_core_options():
    if opt.type is bool:
      # We cannot pass type= when action is 'store_true', go figure!
      parser.add_argument(opt.name, help = opt.help, dest = opt.dest, action = opt.action, default = opt.default_value)
    else:
      parser.add_argument(opt.name, help = opt.help, type=opt.type, dest = opt.dest, action = opt.action, default = opt.default_value)
  return parser.parse_args()
Example #7
0
def _parse_args():
  import platform
  pyversion = platform.python_version()
  if pyversion < '2.7':
    optparser = _create_optparse(prog=__progname__, description=__description__,\
                                      version= __version__)
    (opts, args) = optparser.parse_args()
    return opts
  else:
    import argparse
    parser = argparse.ArgumentParser(prog=__progname__, description=__description__, version=__version__, conflict_handler='resolve' )
    commands = ICommand.implementors()
    for command in commands:
      name = command.command_name()
      option_group = parser.add_argument_group(description="Options added by the {0} subcommand".format(name))
      # Add the custom command aditional options
      for opt in command.extra_options():
        option_group.add_argument(opt.name, help = opt.help, dest = opt.dest, action = opt.action, default = opt.default_value)
    
    # Add wsgid core options
    for opt in _create_core_options():
      parser.add_argument(opt.name, help = opt.help, dest = opt.dest, action = opt.action, default = opt.default_value)
    return parser.parse_args()