def main(argv):
    parser = argparse.ArgumentParser(description="NGSpeasy pipelines")
    parser.add_argument("playbook_path", metavar='/path/to/your_pipeline.yml', type=cmdargs.existed_file)
    parser.add_argument("--play_index", dest="play_index", type=int, help="play index", required=True)
    parser.add_argument("--run_index", dest="run_index", type=int, default=-1, help="run index")
    parser.add_argument("--version", action="version", version="%(prog)s 3.0", help="print software version")
    parser.add_argument("--samples", metavar="/path/to/config.tsv", dest="samples_tsv",
                        type=cmdargs.existed_file, help="List of samples in TSV format")
    parser.add_argument("--vars", dest="var_files", metavar="/path/to/your/vars.yml", help="additional variables",
                        type=cmdargs.existed_file, action="append")
    parser.add_argument("--log_dir", dest="log_dir", type=cmdargs.existed_directory)

    args = parser.parse_args(argv)

    play_index = args.play_index
    run_index = args.run_index
    playbook_path = os.path.abspath(args.playbook_path)
    samples_tsv = os.path.abspath(args.samples_tsv) if args.samples_tsv else None
    var_files = [os.path.abspath(f) for f in args.var_files]

    logger().debug("Command line arguments: %s" % args)
    logger().debug("TSV config path: %s" % samples_tsv)

    pb = playbook_yaml.parse(playbook_path, samples_tsv, var_files, args.log_dir)
    (play_run_vars, play_run_yaml, play_run_name) = pb.play_run(play_index, run_index)

    if args.log_dir is not None:
        init_play_run_logger(args.log_dir, str(play_index) + "_" + play_run_name)

    task = play_run_yaml
    task["hosts"] = "all"

    temp_dir = tempfile.mkdtemp()
    print temp_dir
    try:
        roles_dir = os.path.join(os.path.dirname(playbook_path), "roles")
        if os.path.exists(roles_dir):
            shutil.copytree(roles_dir, os.path.join(temp_dir, "roles"))

        library_dir = os.path.join(os.path.dirname(playbook_path), "library")
        if os.path.exists(library_dir):
            shutil.copytree(library_dir, os.path.join(temp_dir, "library"))

        playbook = os.path.join(temp_dir, "playbook.yml")
        with open(playbook, 'w') as outfile:
            outfile.write(yaml.dump([task], default_flow_style=False))

        run_playbook(temp_dir, play_run_vars)
    finally:
        shutil.rmtree(temp_dir)
示例#2
0
def main(argv):
    parser = argparse.ArgumentParser(description="NGSpyeasy pipeline runner")
    parser.add_argument("playbook_path", metavar='/path/to/your_pipeline.yml', type=cmdargs.existed_file)
    parser.add_argument("--version", action="version", version="%(prog)s 3.0", help="print software version")
    parser.add_argument("--samples", metavar="/path/to/config.tsv", dest="samples_tsv", required=False,
                        type=cmdargs.existed_file, help="List of samples in TSV format")
    parser.add_argument("--vars", dest="var_files", metavar="/path/to/your/vars.yml", help="additional variables",
                        type=cmdargs.existed_file, action="append")
    parser.add_argument("--provider", dest="provider", choices=["local", "lsf"], default="local",
                        help="job scheduler")
    parser.add_argument("--log_dir", dest="log_dir", type=cmdargs.existed_directory)

    args = parser.parse_args(argv)

    if args.log_dir is not None:
        init_main_logger(args.log_dir)

    logger().debug("Command line arguments: %s" % args)

    playbook_path = os.path.abspath(args.playbook_path)
    samples_tsv = os.path.abspath(args.samples_tsv) if args.samples_tsv else None
    var_files = [os.path.abspath(f) for f in args.var_files]

    pb = playbook_yaml.parse(playbook_path, samples_tsv, var_files, args.log_dir)

    logger().info("Starting job executor: provider=%s" % args.provider)
    executor.start(provider=args.provider, log_dir=args.log_dir)

    try:
        for play in pb.plays():
            logger().info("Starting play: %s" % play.name())
            jobs = []
            for name, cmd in play.commands():
                logger().debug("cmd submit: name=%s\n %s\n" % (name, cmd))
                executor.submit(name, cmd)
                jobs.append(name)
            if not wait_for_results(jobs):
                break

    except Exception as e:
        logger().exception(e)
    finally:
        executor.stop()