Esempio n. 1
0
 def parse():
   options, args = old_parser_args()
   if options.trace:
     trace_enable("./%s.trace" % "quickopen")
   if not options.host:
     options.host = 'localhost'
   if not options.port:
     options.port = default_port.get()
   else:
     options.port = int(options.port)
   return options, args
Esempio n. 2
0
 def parse():
     options, args = old_parser_args()
     if options.trace:
         trace_enable("./%s.trace" % "quickopen")
     if not options.host:
         options.host = 'localhost'
     if not options.port:
         options.port = default_port.get()
     else:
         options.port = int(options.port)
     return options, args
Esempio n. 3
0
def main(in_args):
    # poor mans host and port processing to avoid importing OptParse
    port = default_port.get()
    host = 'localhost'
    auto_start = True
    before_args = [
    ]  # remaining after poor-mans parse but befor 'prelaunch' command
    after_args = None
    i = 1
    while i < len(in_args):
        if in_args[i].startswith('--host='):
            host = in_args[i][7:]
            i += 1
            continue

        if in_args[i].startswith('--port='):
            port = in_args[i][7:]
            i += 1
            continue

        if in_args[i] == '--no_auto_start':
            auto_start = False
            i += 1
            continue

        if in_args[i] == 'prelaunch':
            after_args = in_args[i + 1:]
            break

        before_args.append(in_args[i])
        i += 1

    if after_args == None:
        raise Exception("Expected: prelaunch")
    assert len(before_args) == 0
    if len(after_args) == 0:
        after_args.append("search")

    try:
        sys.stdout.write(
            run_command_in_existing(host, port, after_args, auto_start))
        return 0
    except Exception as e:
        sys.stdout.write(str(e) + "\n")
        return -1
Esempio n. 4
0
def main(in_args):
  # poor mans host and port processing to avoid importing OptParse
  port = default_port.get()
  host = 'localhost'
  auto_start = True
  before_args = [] # remaining after poor-mans parse but befor 'prelaunch' command
  after_args = None
  i = 1
  while i < len(in_args):
    if in_args[i].startswith('--host='):
      host = in_args[i][7:]
      i += 1
      continue

    if in_args[i].startswith('--port='):
      port = in_args[i][7:]
      i += 1
      continue

    if in_args[i] == '--no_auto_start':
      auto_start = False
      i += 1
      continue

    if in_args[i] == 'prelaunch':
      after_args = in_args[i+1:]
      break

    before_args.append(in_args[i])
    i += 1

  if after_args == None:
    raise Exception("Expected: prelaunch")
  assert len(before_args) == 0
  if len(after_args) == 0:
    after_args.append("search")

  try:
    sys.stdout.write(run_command_in_existing(host, port, after_args, auto_start))
    return 0
  except Exception as e:
    sys.stdout.write(str(e) + "\n")
    return -1
Esempio n. 5
0
def main(parser):
  """Doesn't parse the arguments here, just find the right subcommand to
  execute."""
  # Create the option parse and add --verbose support.
  parser.add_option('--host', dest='host', action='store', help='Hostname of quickopend server. Default is %i' % default_port.get())
  parser.add_option('--port', dest='port', action='store', help='Port for quickopend')
  parser.add_option('--trace', dest='trace', action='store_true', default=False, help='Records performance tracing information to quickopen.trace')
  parser.add_option('--no_auto_start', dest='auto_start', action='store_false', default=True, help='Prevents quickopend from auto-launching if not started')
  old_parser_args = parser.parse_args
  def parse():
    options, args = old_parser_args()
    if options.trace:
      trace_enable("./%s.trace" % "quickopen")
    if not options.host:
      options.host = 'localhost'
    if not options.port:
      options.port = default_port.get()
    else:
      options.port = int(options.port)
    return options, args
  parser.parse_args = parse

  non_switch_args = [i for i in sys.argv[1:] if not i.startswith('-')]
  if non_switch_args:
    command = Command(non_switch_args[0])
    if command:
      if non_switch_args[0] == 'help':
        CMDhelp.usage_more = ('\n\nCommands are:\n' + '\n'.join([
              '  %-10s %s' % (fn[3:], getdoc(Command(fn[3:])).split('\n')[0].strip())
              for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')]))

      # "fix" the usage and the description now that we know the subcommand.
      GenUsage(parser, non_switch_args[0])
      new_args = list(sys.argv[1:])
      new_args.remove(non_switch_args[0])
      new_args.insert(0, sys.argv[0])
      sys.argv = new_args
      return command(parser)
    else:
      # Not a known command. Default to help.
      print "Unrecognized command: %s\n" % non_switch_args[0]
  else: # default command
    CMDsearch.usage_more = ('\n\nCommands are:\n' + '\n'.join([
          '  %-10s %s' % (fn[3:], getdoc(Command(fn[3:])).split('\n')[0].strip())
          for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')]))
    GenUsage(parser, 'search')
    return CMDsearch(parser)
Esempio n. 6
0
def main(parser):
    """Doesn't parse the arguments here, just find the right subcommand to
  execute."""
    # Create the option parse and add --verbose support.
    parser.add_option('--host',
                      dest='host',
                      action='store',
                      help='Hostname of quickopend server. Default is %i' %
                      default_port.get())
    parser.add_option('--port',
                      dest='port',
                      action='store',
                      help='Port for quickopend')
    parser.add_option(
        '--trace',
        dest='trace',
        action='store_true',
        default=False,
        help='Records performance tracing information to quickopen.trace')
    parser.add_option(
        '--no_auto_start',
        dest='auto_start',
        action='store_false',
        default=True,
        help='Prevents quickopend from auto-launching if not started')
    old_parser_args = parser.parse_args

    def parse():
        options, args = old_parser_args()
        if options.trace:
            trace_enable("./%s.trace" % "quickopen")
        if not options.host:
            options.host = 'localhost'
        if not options.port:
            options.port = default_port.get()
        else:
            options.port = int(options.port)
        return options, args

    parser.parse_args = parse

    non_switch_args = [i for i in sys.argv[1:] if not i.startswith('-')]
    if non_switch_args:
        command = Command(non_switch_args[0])
        if command:
            if non_switch_args[0] == 'help':
                CMDhelp.usage_more = ('\n\nCommands are:\n' + '\n'.join([
                    '  %-10s %s' %
                    (fn[3:], getdoc(Command(fn[3:])).split('\n')[0].strip())
                    for fn in dir(sys.modules[__name__])
                    if fn.startswith('CMD')
                ]))

            # "fix" the usage and the description now that we know the subcommand.
            GenUsage(parser, non_switch_args[0])
            new_args = list(sys.argv[1:])
            new_args.remove(non_switch_args[0])
            new_args.insert(0, sys.argv[0])
            sys.argv = new_args
            return command(parser)
        else:
            # Not a known command. Default to help.
            print "Unrecognized command: %s\n" % non_switch_args[0]
    else:  # default command
        CMDsearch.usage_more = ('\n\nCommands are:\n' + '\n'.join([
            '  %-10s %s' %
            (fn[3:], getdoc(Command(fn[3:])).split('\n')[0].strip())
            for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')
        ]))
        GenUsage(parser, 'search')
        return CMDsearch(parser)