Example #1
0
def main():
    # Parse command line options
    parser = argparse.ArgumentParser()
    group = parser.add_mutually_exclusive_group()
    parser.add_argument("-D", "--base-dir", action="store", type=utf8_decoder,
                        help="base directory for problem to make "
                        "(CWD by default)")
    parser.add_argument("-l", "--list", action="store_true", default=False,
                        help="list actions that cmsMake is aware of")
    parser.add_argument("-c", "--clean", action="store_true", default=False,
                        help="clean all generated files")
    parser.add_argument("-a", "--all", action="store_true", default=False,
                        help="make all targets")
    group.add_argument("-y", "--yes",
                       dest="assume", action="store_const", const='y',
                       help="answer yes to all questions")
    group.add_argument("-n", "--no",
                       dest="assume", action="store_const", const='n',
                       help="answer no to all questions")
    parser.add_argument("-d", "--debug", action="store_true", default=False,
                        help="enable debug messages")
    parser.add_argument("targets", action="store", type=utf8_decoder,
                        nargs="*", metavar="target", help="target to build")
    options = parser.parse_args()

    base_dir = options.base_dir
    if base_dir is None:
        base_dir = os.getcwd()
    else:
        base_dir = os.path.abspath(base_dir)

    assume = options.assume

    task_type = detect_task_type(base_dir)
    yaml_conf = parse_task_yaml(base_dir)
    actions = build_action_list(base_dir, task_type, yaml_conf)
    exec_tree, generated_list = build_execution_tree(actions)

    if [len(options.targets) > 0, options.list, options.clean,
            options.all].count(True) > 1:
        parser.error("Too many commands")

    if options.list:
        print("Task name: %s" % (detect_task_name(base_dir)))
        print("Task type: %s %s" % (task_type[0], task_type[1]))
        print("Available operations:")
        for entry in actions:
            print("  %s: %s -> %s" %
                  (entry[3], ", ".join(entry[0]), ", ".join(entry[1])))

    elif options.clean:
        print("Cleaning")
        clean(base_dir, generated_list)

    elif options.all:
        print("Making all targets")
        print()
        try:
            execute_multiple_targets(base_dir, exec_tree,
                                     generated_list, debug=options.debug,
                                     assume=assume)

        # After all work, possibly clean the left-overs of testing
        finally:
            clean_test_env()

    else:
        try:
            execute_multiple_targets(base_dir, exec_tree,
                                     options.targets, debug=options.debug,
                                     assume=assume)

        # After all work, possibly clean the left-overs of testing
        finally:
            clean_test_env()
Example #2
0
def main():
    # Parse command line options
    parser = argparse.ArgumentParser()
    group = parser.add_mutually_exclusive_group()
    parser.add_argument("-D",
                        "--base-dir",
                        action="store",
                        type=utf8_decoder,
                        help="base directory for problem to make "
                        "(CWD by default)")
    parser.add_argument("-l",
                        "--list",
                        action="store_true",
                        default=False,
                        help="list actions that cmsMake is aware of")
    parser.add_argument("-c",
                        "--clean",
                        action="store_true",
                        default=False,
                        help="clean all generated files")
    parser.add_argument("-a",
                        "--all",
                        action="store_true",
                        default=False,
                        help="make all targets")
    group.add_argument("-y",
                       "--yes",
                       dest="assume",
                       action="store_const",
                       const='y',
                       help="answer yes to all questions")
    group.add_argument("-n",
                       "--no",
                       dest="assume",
                       action="store_const",
                       const='n',
                       help="answer no to all questions")
    parser.add_argument("-d",
                        "--debug",
                        action="store_true",
                        default=False,
                        help="enable debug messages")
    parser.add_argument("targets",
                        action="store",
                        type=utf8_decoder,
                        nargs="*",
                        metavar="target",
                        help="target to build")
    options = parser.parse_args()

    base_dir = options.base_dir
    if base_dir is None:
        base_dir = os.getcwd()
    else:
        base_dir = os.path.abspath(base_dir)

    assume = options.assume

    task_type = detect_task_type(base_dir)
    yaml_conf = parse_task_yaml(base_dir)
    actions = build_action_list(base_dir, task_type, yaml_conf)
    exec_tree, generated_list = build_execution_tree(actions)

    if [len(options.targets) > 0, options.list, options.clean, options.all
        ].count(True) > 1:
        parser.error("Too many commands")

    if options.list:
        print("Task name: %s" % (detect_task_name(base_dir)))
        print("Task type: %s %s" % (task_type[0], task_type[1]))
        print("Available operations:")
        for entry in actions:
            print("  %s: %s -> %s" %
                  (entry[3], ", ".join(entry[0]), ", ".join(entry[1])))

    elif options.clean:
        print("Cleaning")
        clean(base_dir, generated_list)

    elif options.all:
        print("Making all targets")
        print()
        try:
            execute_multiple_targets(base_dir,
                                     exec_tree,
                                     generated_list,
                                     debug=options.debug,
                                     assume=assume)

        # After all work, possibly clean the left-overs of testing
        finally:
            clean_test_env()

    else:
        try:
            execute_multiple_targets(base_dir,
                                     exec_tree,
                                     options.targets,
                                     debug=options.debug,
                                     assume=assume)

        # After all work, possibly clean the left-overs of testing
        finally:
            clean_test_env()