Exemplo n.º 1
0
def main():
    '''
  Run the command
  :return:
  '''
    # verify if the environment variables are correctly set
    check_environment()

    # create the argument parser
    parser = create_parser()

    # if no argument is provided, print help and exit
    if len(sys.argv[1:]) == 0:
        parser.print_help()
        return 0

    # insert the boolean values for some of the options
    sys.argv = config.insert_bool_values(sys.argv)

    try:
        # parse the args
        args, unknown_args = parser.parse_known_args()
    except ValueError as ex:
        Log.error("Error while parsing arguments: %s", str(ex))
        Log.debug(traceback.format_exc())
        sys.exit(1)

    command_line_args = vars(args)

    # command to be execute
    command = command_line_args['subcommand']

    # file resources to be cleaned when exit
    files = []

    if command not in ('help', 'version'):
        log.set_logging_level(command_line_args)
        command_line_args = extract_common_args(command, parser,
                                                command_line_args)
        # bail out if args are empty
        if not command_line_args:
            return 1
        # register dirs cleanup function during exit
        files.append(command_line_args['override_config_file'])

    atexit.register(cleanup, files)

    # print the input parameters, if verbose is enabled
    Log.debug(command_line_args)

    start = time.time()
    resp = run(command, parser, command_line_args, unknown_args)
    response.render(resp)
    end = time.time()

    if command not in ('help', 'version'):
        sys.stdout.flush()
        Log.info('Elapsed time: %.3fs.', (end - start))

    return 0 if response.isAllSuccessful(resp) else 1
Exemplo n.º 2
0
def main():
  '''
  Run the command
  :return:
  '''
  # verify if the environment variables are correctly set
  check_environment()

  # create the argument parser
  parser = create_parser()

  # if no argument is provided, print help and exit
  if len(sys.argv[1:]) == 0:
    parser.print_help()
    return 0

  # insert the boolean values for some of the options
  sys.argv = config.insert_bool_values(sys.argv)

  try:
    # parse the args
    args, unknown_args = parser.parse_known_args()
  except ValueError as ex:
    Log.error("Error while parsing arguments: %s", str(ex))
    Log.debug(traceback.format_exc())
    sys.exit(1)

  command_line_args = vars(args)

  # command to be execute
  command = command_line_args['subcommand']

  # file resources to be cleaned when exit
  files = []

  if command not in ('help', 'version'):
    log.set_logging_level(command_line_args)
    command_line_args = extract_common_args(command, parser, command_line_args)
    # bail out if args are empty
    if not command_line_args:
      return 1
    # register dirs cleanup function during exit
    files.append(command_line_args['override_config_file'])

  atexit.register(cleanup, files)

  # print the input parameters, if verbose is enabled
  Log.debug(command_line_args)

  start = time.time()
  resp = run(command, parser, command_line_args, unknown_args)
  response.render(resp)
  end = time.time()

  if command not in ('help', 'version'):
    sys.stdout.flush()
    Log.info('Elapsed time: %.3fs.', (end - start))

  return 0 if response.isAllSuccessful(resp) else 1
Exemplo n.º 3
0
    def initializeFromRC(cls, rcfile):
        if len(cls.cmdmap) > 0:
            return
        effective_rc = (rcfile, HERON_RC)[rcfile is None]
        Log.debug('Effective RC file is %s', effective_rc)
        if os.path.exists(effective_rc):
            with open(effective_rc) as f:
                cls.cmdmap['*']['*'] = collections.defaultdict(dict)
                cls.cmdmap['*']['*']['*'] = ''
                for line in f:
                    m = heron_command_pattern.match(line)
                    app, value, command, env = '', '', '', ''
                    if m is not None:
                        value = cls.remove_comments(
                            m.group(4).rstrip(os.linesep))
                        app = (m.group(1), '')[m.group(1) is None
                                               or m.group(1) == '']
                        command = (m.group(2), '')[m.group(2) is None
                                                   or m.group(1) == '']
                        env = (m.group(3), '')[m.group(3) is None
                                               or m.group(2) == '']
                    else:
                        continue
                    # make sure that all the single args have a boolean value
                    # associated so that we can load the args to a key value
                    # structure
                    args_list = config.insert_bool_values(value.split())
                    args_list_string = ' '.join(args_list)
                    if not command or not app or not env:
                        Log.warn(
                            "heronrc config entry %s does not have key parameters (command:app:env) ",
                            line)
                        continue
                    if app not in cls.cmdmap:
                        cls.cmdmap[app] = collections.defaultdict(dict)

                    if command in cls.cmdmap[app] and env in cls.cmdmap[app][
                            command]:
                        cls.cmdmap[app][command][env] = cls.cmdmap[app][
                            command][env] + ' ' + args_list_string
                    else:
                        cls.cmdmap[app][command][env] = args_list_string
            Log.debug("RC cmdmap %s", json.dumps(cls.cmdmap))
        else:
            Log.debug("%s is not an existing file", effective_rc)
Exemplo n.º 4
0
def execute(handlers):
  '''
  Run the command
  :return:
  '''
  # verify if the environment variables are correctly set
  check_environment()

  # create the argument parser
  parser = create_parser(handlers)

  # if no argument is provided, print help and exit
  if len(sys.argv[1:]) == 0:
    parser.print_help()
    return 0

  # insert the boolean values for some of the options
  sys.argv = config.insert_bool_values(sys.argv)

  try:
    # parse the args
    args, unknown_args = parser.parse_known_args()
  except ValueError as ex:
    Log.error("Error while parsing arguments: %s", str(ex))
    Log.debug(traceback.format_exc())
    sys.exit(1)

  command_line_args = vars(args)

  # set log level
  log.set_logging_level(command_line_args)
  Log.debug("Input Command Line Args: %s", command_line_args)

  # command to be execute
  command = command_line_args['subcommand']

  # print the input parameters, if verbose is enabled
  Log.debug("Processed Command Line Args: %s", command_line_args)

  results = run(handlers, command, parser, command_line_args, unknown_args)

  return 0 if result.is_successful(results) else 1
Exemplo n.º 5
0
  def initializeFromRC(cls, rcfile):
    if len(cls.cmdmap) > 0:
      return
    effective_rc = (rcfile, HERON_RC)[rcfile is None]
    Log.debug('Effective RC file is %s', effective_rc)
    if os.path.exists(effective_rc):
      with open(effective_rc) as f:
        cls.cmdmap['*']['*'] = collections.defaultdict(dict)
        cls.cmdmap['*']['*']['*'] = ''
        for line in f:
          m = heron_command_pattern.match(line)
          app, value, command, env = '', '', '', ''
          if m is not None:
            value = cls.remove_comments(m.group(4).rstrip(os.linesep))
            app = (m.group(1), '')[m.group(1) is None or m.group(1) == '']
            command = (m.group(2), '')[m.group(2) is None or m.group(1) == '']
            env = (m.group(3), '')[m.group(3) is None or m.group(2) == '']
          else:
            continue
          # make sure that all the single args have a boolean value
          # associated so that we can load the args to a key value
          # structure
          args_list = config.insert_bool_values(value.split())
          args_list_string = ' '.join(args_list)
          if not  command or not app or not env:
            Log.warn("heronrc config entry %s does not have key parameters (command:app:env) ",
                     line)
            continue
          if app not in cls.cmdmap:
            cls.cmdmap[app] = collections.defaultdict(dict)

          if command in cls.cmdmap[app] and env in cls.cmdmap[app][command]:
            cls.cmdmap[app][command][env] = cls.cmdmap[app][command][env] + ' ' + args_list_string
          else:
            cls.cmdmap[app][command][env] = args_list_string
      Log.debug("RC cmdmap %s", json.dumps(cls.cmdmap))
    else:
      Log.debug("%s is not an existing file", effective_rc)
Exemplo n.º 6
0
def execute(handlers, local_commands):
  '''
  Run the command
  :return:
  '''
  # verify if the environment variables are correctly set
  check_environment()

  # create the argument parser
  parser = create_parser(handlers)

  # if no argument is provided, print help and exit
  if len(sys.argv[1:]) == 0:
    parser.print_help()
    return 0

  # insert the boolean values for some of the options
  sys.argv = config.insert_bool_values(sys.argv)

  try:
    # parse the args
    args, unknown_args = parser.parse_known_args()
  except ValueError as ex:
    Log.error("Error while parsing arguments: %s", str(ex))
    Log.debug(traceback.format_exc())
    sys.exit(1)

  command_line_args = vars(args)

  # set log level
  log.set_logging_level(command_line_args)
  Log.debug("Input Command Line Args: %s", command_line_args)

# command to be execute
  command = command_line_args['subcommand']
  is_local_command = command in local_commands

  if command == 'version':
    results = run(handlers, command, parser, command_line_args, unknown_args)
    return 0 if result.is_successful(results) else 1

  if not is_local_command:
    log.set_logging_level(command_line_args)
    Log.debug("Input Command Line Args: %s", command_line_args)

    # determine the mode of deployment
    command_line_args = extract_common_args(command, parser, command_line_args)
    command_line_args = deployment_mode(command, parser, command_line_args)

    # bail out if args are empty
    if not command_line_args:
      return 1

    # register dirs cleanup function during exit
    if command_line_args['deploy_mode'] == config.DIRECT_MODE and command != "version":
      cleaned_up_files.append(command_line_args['override_config_file'])
      atexit.register(cleanup, cleaned_up_files)

  # print the input parameters, if verbose is enabled
  Log.debug("Processed Command Line Args: %s", command_line_args)

  start = time.time()
  results = run(handlers, command, parser, command_line_args, unknown_args)
  if not is_local_command:
    result.render(results)
  end = time.time()

  if not is_local_command:
    sys.stdout.flush()
    Log.debug('Elapsed time: %.3fs.', (end - start))

  return 0 if result.is_successful(results) else 1
Exemplo n.º 7
0
def execute(handlers, local_commands):
  '''
  Run the command
  :return:
  '''
  # verify if the environment variables are correctly set
  check_environment()

  # create the argument parser
  parser = create_parser(handlers)

  # if no argument is provided, print help and exit
  if len(sys.argv[1:]) == 0:
    parser.print_help()
    return 0

  # insert the boolean values for some of the options
  sys.argv = config.insert_bool_values(sys.argv)

  try:
    # parse the args
    args, unknown_args = parser.parse_known_args()
  except ValueError as ex:
    Log.error("Error while parsing arguments: %s", str(ex))
    Log.debug(traceback.format_exc())
    sys.exit(1)

  command_line_args = vars(args)

  # set log level
  log.set_logging_level(command_line_args)
  Log.debug("Input Command Line Args: %s", command_line_args)

# command to be execute
  command = command_line_args['subcommand']
  is_local_command = command in local_commands

  if command == 'version':
    results = run(handlers, command, parser, command_line_args, unknown_args)
    return 0 if result.is_successful(results) else 1

  if not is_local_command:
    log.set_logging_level(command_line_args)
    Log.debug("Input Command Line Args: %s", command_line_args)

    # determine the mode of deployment
    command_line_args = extract_common_args(command, parser, command_line_args)
    command_line_args = deployment_mode(command, parser, command_line_args)

    # bail out if args are empty
    if not command_line_args:
      return 1

    # register dirs cleanup function during exit
    if command_line_args['deploy_mode'] == config.DIRECT_MODE and command != "version":
      cleaned_up_files.append(command_line_args['override_config_file'])
      atexit.register(cleanup, cleaned_up_files)

  # print the input parameters, if verbose is enabled
  Log.debug("Processed Command Line Args: %s", command_line_args)

  start = time.time()
  results = run(handlers, command, parser, command_line_args, unknown_args)
  if not is_local_command:
    result.render(results)
  end = time.time()

  if not is_local_command:
    sys.stdout.flush()
    Log.debug('Elapsed time: %.3fs.', (end - start))

  return 0 if result.is_successful(results) else 1