Esempio n. 1
0
def validate_configfile(ctx, param, value):
  """ Validate the main configfile presence """
  configfile = value
  if configfile is None:
    raise click.BadParameter('not specified - check --help')
  try:
    utils.validate_file(configfile)
  except InvalidValueException as exception_obj:
    raise click.BadParameter(str(exception_obj))
  return configfile
Esempio n. 2
0
def find_targetfiles(ctx, param, value):
  """ Validate and find targetfiles """
  # if not supplied, load from config
  filenames = value
  from_config = False
  if not filenames:
    from_config = True
    filenames = ctx.obj['config']['targets']['files']

  targets_dir = ctx.obj['config']['targets']['dir']
  targetfiles = [os.path.join(targets_dir, x) for x in filenames]

  # supplied by the user  - validate them
  if not from_config:
    for filepath in targetfiles:
      try:
        utils.validate_file(filepath)
      except InvalidValueException as invalid_value_exception:
        click.echo(click.style(str(invalid_value_exception), fg='red'))
        ctx.exit(1)

  return targetfiles
Esempio n. 3
0
def _find_actionfile(action, ctx, actionfile):
  """ Return default action file if empty - else validate input """
  if actionfile is None:
    return _find_default_actionfile(ctx, action)
  utils.validate_file(actionfile)
  return actionfile
Esempio n. 4
0
def _find_default_actionfile(ctx, action):
  """ Find the default action file depending on the action """
  actionfile = os.path.join(ctx.obj['config']['actions']['dir'], '%s.json' % action)
  utils.validate_file(actionfile)
  return actionfile