Exemplo n.º 1
0
def run(package_deps, args):
  from recipe_engine import run as recipe_run
  from recipe_engine import loader
  from recipe_engine import package
  from recipe_engine.third_party import annotator

  def get_properties_from_args(args):
    properties = dict(x.split('=', 1) for x in args)
    for key, val in properties.iteritems():
      try:
        properties[key] = json.loads(val)
      except (ValueError, SyntaxError):
        pass  # If a value couldn't be evaluated, keep the string version
    return properties

  def get_properties_from_file(filename):
    properties_file = sys.stdin if filename == '-' else open(filename)
    properties = json.load(properties_file)
    assert isinstance(properties, dict)
    return properties

  def get_properties_from_json(props):
    return json.loads(props)

  arg_properties = get_properties_from_args(args.props)
  assert len(filter(bool,
      [arg_properties, args.properties_file, args.properties])) <= 1, (
          'Only one source of properties is allowed')
  if args.properties:
    properties = get_properties_from_json(args.properties)
  elif args.properties_file:
    properties = get_properties_from_file(args.properties_file)
  else:
    properties = arg_properties

  properties['recipe'] = args.recipe

  os.environ['PYTHONUNBUFFERED'] = '1'
  os.environ['PYTHONIOENCODING'] = 'UTF-8'

  universe = loader.RecipeUniverse(package_deps)

  workdir = (args.workdir or
      os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir'))
  logging.info('Using %s as work directory' % workdir)
  if not os.path.exists(workdir):
    os.makedirs(workdir)

  old_cwd = os.getcwd()
  os.chdir(workdir)
  try:
    ret = recipe_run.run_steps(
        properties, annotator.StructuredAnnotationStream(), universe=universe)
    return ret.status_code
  finally:
    os.chdir(old_cwd)
Exemplo n.º 2
0
def run(package_deps, args):
    from recipe_engine import run as recipe_run
    from recipe_engine import loader
    from recipe_engine import package
    from recipe_engine.third_party import annotator

    def get_properties_from_args(args):
        properties = dict(x.split('=', 1) for x in args)
        for key, val in properties.iteritems():
            try:
                properties[key] = ast.literal_eval(val)
            except (ValueError, SyntaxError):
                pass  # If a value couldn't be evaluated, keep the string version
        return properties

    def get_properties_from_file(filename):
        properties_file = sys.stdin if filename == '-' else open(filename)
        properties = ast.literal_eval(properties_file.read())
        assert isinstance(properties, dict)

    def get_properties_from_json(args):
        return ast.literal_eval(args.properties)

    arg_properties = get_properties_from_args(args.props)
    assert len(
        filter(bool, [arg_properties, args.properties_file, args.properties
                      ])) <= 1, ('Only one source of properties is allowed')
    if args.properties:
        properties = get_properties_from_json(args.properties)
    elif args.properties_file:
        properties = get_properties_from_file(args.properties_file)
    else:
        properties = arg_properties

    properties['recipe'] = args.recipe

    os.environ['PYTHONUNBUFFERED'] = '1'
    os.environ['PYTHONIOENCODING'] = 'UTF-8'

    universe = loader.RecipeUniverse(package_deps)

    workdir = (args.workdir or os.path.join(
        os.path.dirname(os.path.realpath(__file__)), 'workdir'))
    logging.info('Using %s as work directory' % workdir)
    if not os.path.exists(workdir):
        os.makedirs(workdir)

    old_cwd = os.getcwd()
    os.chdir(workdir)
    try:
        ret = recipe_run.run_steps(properties,
                                   annotator.StructuredAnnotationStream(),
                                   universe=universe)
        return ret.status_code
    finally:
        os.chdir(old_cwd)
Exemplo n.º 3
0
def run(package_deps, args):
  from recipe_engine import run as recipe_run
  from recipe_engine import loader
  from recipe_engine import package
  from recipe_engine import step_runner
  from recipe_engine import stream

  def get_properties_from_args(args):
    properties = dict(x.split('=', 1) for x in args)
    for key, val in properties.iteritems():
      try:
        properties[key] = json.loads(val)
      except (ValueError, SyntaxError):
        pass  # If a value couldn't be evaluated, keep the string version
    return properties

  def get_properties_from_file(filename):
    properties_file = sys.stdin if filename == '-' else open(filename)
    properties = json.load(properties_file)
    assert isinstance(properties, dict)
    return properties

  def get_properties_from_json(props):
    return json.loads(props)

  arg_properties = get_properties_from_args(args.props)
  assert len(filter(bool,
      [arg_properties, args.properties_file, args.properties])) <= 1, (
          'Only one source of properties is allowed')
  if args.properties:
    properties = get_properties_from_json(args.properties)
  elif args.properties_file:
    properties = get_properties_from_file(args.properties_file)
  else:
    properties = arg_properties

  properties['recipe'] = args.recipe

  os.environ['PYTHONUNBUFFERED'] = '1'
  os.environ['PYTHONIOENCODING'] = 'UTF-8'

  _, config_file = get_package_config(args)
  universe = loader.UniverseView(
      loader.RecipeUniverse(
          package_deps, config_file), package_deps.root_package)

  workdir = (args.workdir or
      os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir'))
  logging.info('Using %s as work directory' % workdir)
  if not os.path.exists(workdir):
    os.makedirs(workdir)

  old_cwd = os.getcwd()
  os.chdir(workdir)
  stream_engine = stream.ProductStreamEngine(
      stream.StreamEngineInvariants(),
      stream.AnnotatorStreamEngine(sys.stdout))

  try:
    ret = recipe_run.run_steps(
        properties, stream_engine,
        step_runner.SubprocessStepRunner(stream_engine),
        universe=universe)

  finally:
    os.chdir(old_cwd)

  return handle_recipe_return(ret, args.output_result_json, stream_engine)