@catch(AzkabanError)
def main():
  """AzkabanPig entry point."""
  args = docopt(__doc__)
  cfg = Config()
  # activate logging
  logger = lg.getLogger()
  logger.setLevel(lg.DEBUG)
  handler = cfg.get_file_handler('azkabanpig')
  if handler:
    logger.addHandler(handler)
  # capture pesky unverified requests warnings
  suppress_urllib_warnings()
  # handle this command separately
  if args['--log']:
    if handler:
      sys.stdout.write('%s\n' % (handler.baseFilename, ))
      sys.exit(0)
    else:
      raise AzkabanError('No log file active.')
  # create project
  paths = args['PATH']
  jars = args['--jar'] or []
  if args['--url']:
    session = Session(url=args['--url'], config=cfg)
  else:
    alias = args['--alias'] or cfg.get_option('azkabanpig', 'default.alias')
    session = Session.from_alias(alias=alias, config=cfg)
  project = _PigProject(
    name=args['--project'] or cfg.get_option('azkabanpig', 'default.project'),
    paths=paths,
    pig_type=args['--type'],
  )
  project.properties = {
    'user.to.proxy': session.user,
    'pig.additional.jars': ','.join(abspath(j).lstrip(sep) for j in jars),
  }
  project.properties.update(
    opt.split('=', 1)
    for opt in args['--option']
    if '=' in opt
  )
  job_paths = (opt for opt in args['--option'] if not '=' in opt)
  for i, job_path in enumerate(job_paths):
    if not exists(job_path):
      raise AzkabanError(
        'Invalid `--option`: %s\nOptions should point to an existing job file'
        ' or be of the form `key=value`.'
        % (job_path, )
      )
    project.add_file(abspath(job_path), '%s.properties' % (i, ))
  for fpath in args['--file']:
    if exists(fpath) and not isabs(fpath) and pardir in relpath(fpath):
      # We give a more useful error message than what `add_file` would raise.
      # For simplicity, AzkabanPig doesn't allow directly configuring the
      # archive path of included files (in the vast majority of cases, a
      # relative include is much more convenient than absolute, so we can't
      # just use the absolute path).
      raise AzkabanError(
        'Included files must either be below the CWD or be included using an '
        'absolute path.\nUse an absolute path to include %s'
        % (fpath, )
      )
    project.add_file(fpath)
  for jar in jars:
    project.add_file(abspath(jar))
  with temppath() as tpath:
    project.build(tpath)
    while True:
      try:
        session.upload_project(project, tpath)
      except AzkabanError:
        session.create_project(project, project)
      else:
        break
  res = session.run_workflow(project, basename(paths[-1]))
  exe = Execution(session, res['execid'])
  if args['--background']:
    sys.stdout.write('Execution running at %s\n' % (exe.url, ))
  else:
    try:
      for line in project.logs(exe):
        sys.stdout.write('%s\n' % (line.encode('utf-8'), ))
    except KeyboardInterrupt:
      choice = raw_input('\nCancel execution [yN]? ').lower()
      if choice and choice[0] == 'y':
        sys.stdout.write('Killing... ')
        exe.cancel()
        sys.stdout.write('Done.\n')
      else:
        sys.stdout.write('Execution still running at %s\n' % (exe.url, ))
dataset/ETHPy150Open mtth/azkaban/azkaban/ext/pig.py/main/original