def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-f',
                        '--file',
                        default='makefile.uni.py',
                        help='sets the build script')
    parser.add_argument('-d',
                        '--destination',
                        default='.',
                        help='output directory (base for download and build)')
    parser.add_argument('-s',
                        '--set',
                        action='append',
                        help='set configuration parameters')
    parser.add_argument('-g',
                        '--graph',
                        action='store_true',
                        help='update dependency graph')
    parser.add_argument('target', nargs='*', help='make target')
    args = parser.parse_args()

    init_config(args)

    for d in ["download", "build", "progress"]:
        if not os.path.exists(config["paths"][d]):
            os.makedirs(config["paths"][d])

    time_format = "%(asctime)-15s %(message)s"
    logging.basicConfig(format=time_format, level=logging.DEBUG)

    logging.debug("building dependency graph")
    manager = TaskManager()
    imp.load_source("build", args.file)
    build_graph = manager.create_graph({})
    assert isinstance(build_graph, nx.DiGraph)

    if args.graph:
        draw_graph(build_graph, "graph")

    cycles = list(nx.simple_cycles(build_graph))
    if cycles:
        logging.error("There are cycles in the build graph")
        for cycle in cycles:
            logging.info(", ".join(cycle))
        return 1

    if args.target:
        for target in args.target:
            manager.enable(build_graph, target)
    else:
        manager.enable_all(build_graph)

    logging.debug("processing tasks")
    independent = extract_independent(build_graph)

    while independent:
        for node in independent:
            task = build_graph.node[node]['task']
            try:
                task.prepare()
                if build_graph.node[node][
                        'enable'] and not task.already_processed():
                    progress = Progress()
                    progress.set_change_callback(progress_callback)
                    if isinstance(task, Project):
                        logging.debug("finished project \"{}\"".format(node))
                    else:
                        logging.debug("run task \"{}\"".format(node))
                    if task.process(progress):
                        task.mark_success()
                    else:
                        if task.fail_behaviour == Task.FailBehaviour.FAIL:
                            logging.critical("task %s failed", node)
                            return 1
                        elif task.fail_behaviour == Task.FailBehaviour.SKIP_PROJECT:
                            recursive_remove(build_graph, node)
                            break
                        elif task.fail_behaviour == Task.FailBehaviour.CONTINUE:
                            # nothing to do
                            pass
                    sys.stdout.write("\n")
            except Exception, e:
                logging.error("Task {} failed: {}".format(task.name, e))
                raise

            build_graph.remove_node(node)

        independent = extract_independent(build_graph)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', '--file', default='makefile.uni.py', help='sets the build script')
    parser.add_argument('-d', '--destination', default='.', help='output directory (base for download and build)')
    parser.add_argument('-s', '--set', action='append', help='set configuration parameters')
    parser.add_argument('-g', '--graph', action='store_true', help='update dependency graph')
    parser.add_argument('target', nargs='*', help='make target')
    args = parser.parse_args()

    init_config(args)

    for d in ["download", "build", "progress"]:
        if not os.path.exists(config["paths"][d]):
            os.makedirs(config["paths"][d])

    time_format = "%(asctime)-15s %(message)s"
    logging.basicConfig(format=time_format, level=logging.DEBUG)

    logging.debug("building dependency graph")
    manager = TaskManager()
    imp.load_source("build", args.file)
    build_graph = manager.create_graph({})
    assert isinstance(build_graph, nx.DiGraph)

    if args.graph:
        draw_graph(build_graph, "graph")

    cycles = list(nx.simple_cycles(build_graph))
    if cycles:
        logging.error("There are cycles in the build graph")
        for cycle in cycles:
            logging.info(", ".join(cycle))
        return 1

    if args.target:
        for target in args.target:
            manager.enable(build_graph, target)
    else:
        manager.enable_all(build_graph)

    logging.debug("processing tasks")
    independent = extract_independent(build_graph)

    while independent:
        for node in independent:
            task = build_graph.node[node]['task']
            try:
                task.prepare()
                if build_graph.node[node]['enable'] and not task.already_processed():
                    progress = Progress()
                    progress.set_change_callback(progress_callback)
                    if isinstance(task, Project):
                        logging.debug("finished project \"{}\"".format(node))
                    else:
                        logging.debug("run task \"{}\"".format(node))
                    if task.process(progress):
                        task.mark_success()
                    else:
                        if task.fail_behaviour == Task.FailBehaviour.FAIL:
                            logging.critical("task %s failed", node)
                            return 1
                        elif task.fail_behaviour == Task.FailBehaviour.SKIP_PROJECT:
                            recursive_remove(build_graph, node)
                            break
                        elif task.fail_behaviour == Task.FailBehaviour.CONTINUE:
                            # nothing to do
                            pass
                    sys.stdout.write("\n")
            except Exception, e:
                logging.error("Task {} failed: {}".format(task.name, e))
                raise

            build_graph.remove_node(node)

        independent = extract_independent(build_graph)
def main():
    time_format = "%(asctime)-15s %(message)s"
    logging.basicConfig(format=time_format, level=logging.DEBUG)
    logging.debug("  ==== Unimake.py started ===  ")

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-f',
        '--file',
        metavar='file',
        default='makefile.uni.py',
        help='sets the build script file. eg: -f makefile.uni.py')
    parser.add_argument(
        '-d',
        '--destination',
        metavar='path',
        default='.',
        help=
        'output directory for all generated folder and files .eg: -d E:/MO2')
    parser.add_argument(
        '-s',
        '--set',
        metavar='option=value',
        action='append',
        help=
        'set configuration parameters. most of them are in config.py. eg: -s paths.build=build'
    )
    parser.add_argument('-g',
                        '--graph',
                        action='store_true',
                        help='update dependency graph')
    parser.add_argument('-b',
                        '--builddir',
                        metavar='directory',
                        default='build',
                        help='sets build directory. eg: -b build')
    parser.add_argument('-p',
                        '--progressdir',
                        metavar='directory',
                        default='progress',
                        help='sets progress directory. eg: -p progress')
    parser.add_argument('-i',
                        '--installdir',
                        metavar='directory',
                        default='install',
                        help='set install directory. eg: -i directory')
    parser.add_argument(
        'target',
        nargs='*',
        help=
        'make this target. eg: modorganizer-archive modorganizer-uibase (you need to delete the progress file. will be fixed eventually)'
    )
    args = parser.parse_args()

    init_config(args)

    for d in ["download", "build", "progress", "install"]:
        if not os.path.exists(config["paths"][d]):
            os.makedirs(config["paths"][d])

    dump_config()
    if not check_config():
        logging.error("Missing pre requisite")
        return False

    logging.debug("  Build: args.target=%s", args.target)
    logging.debug("  Build: args.destination=%s", args.destination)

    for target in args.target:
        if target == "Check":
            return True

    logging.debug("building dependency graph")
    manager = TaskManager()
    machinery.SourceFileLoader(args.builddir, args.file).load_module()
    build_graph = manager.create_graph({})
    assert isinstance(build_graph, nx.DiGraph)

    if args.graph:
        draw_graph(build_graph, "graph")

    cycles = list(nx.simple_cycles(build_graph))
    if cycles:
        logging.error("There are cycles in the build graph")
        for cycle in cycles:
            logging.info(", ".join(cycle))
        return 1

    ShowOnly = config['show_only']
    RetrieveOnly = config['retrieve_only']
    ToolsOnly = config['tools_only']

    if args.target:
        for target in args.target:
            manager.enable(build_graph, target)
    else:
        manager.enable_all(build_graph)

    logging.debug("processing tasks")
    independent = extract_independent(build_graph)

    while independent:
        for node in independent:
            task = build_graph.node[node]['task']
            try:
                task.prepare()
                if build_graph.node[node][
                        'enable'] and not task.already_processed():
                    progress = Progress()
                    progress.set_change_callback(progress_callback)
                    if isinstance(task, Project):
                        logging.debug("finished project \"%s\"", node)
                    else:
                        logging.debug("run task \"%s\"", node)
                    if not ShowOnly:
                        Retrieve = (-1 != node.find("retrieve")) or (
                            -1 != node.find("download")) or (
                                -1 != node.find("repository"))
                        Tool = (-1 == node.find("modorganizer")) and (
                            -1 == node.find("githubpp"))
                        DoProcess = (Retrieve or not RetrieveOnly) and (
                            Tool or not ToolsOnly)
                        if DoProcess:
                            if task.process(progress):
                                task.mark_success()
                            else:
                                if task.fail_behaviour == Task.FailBehaviour.FAIL:
                                    logging.critical("task %s failed", node)
                                    exitcode = 1
                                    return 1
                                elif task.fail_behaviour == Task.FailBehaviour.SKIP_PROJECT:
                                    recursive_remove(build_graph, node)
                                    break
                                elif task.fail_behaviour == Task.FailBehaviour.CONTINUE:
                                    # nothing to do
                                    pass
                        else:
                            logging.critical("task %s skipped", node)
                        sys.stdout.write("\n")
            except Exception as e:
                logging.error("Task %s failed: %s", task.name, e)
                raise

            build_graph.remove_node(node)

        independent = extract_independent(build_graph)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-f", "--file", default="makefile.uni.py", help="sets the build script")
    parser.add_argument("-d", "--destination", default=".", help="output directory (base for download and build)")
    parser.add_argument("-s", "--set", action="append", help="set configuration parameters")
    parser.add_argument("-g", "--graph", action="store_true", help="update dependency graph")
    parser.add_argument("target", nargs="*", help="make target")
    args = parser.parse_args()

    init_config(args)
    script_dir = os.path.abspath(os.path.dirname(__file__))
    config.cfg["paths"]["root"] = script_dir
    print(config.get("paths.root"))

    from buildtools import os_utils

    os_utils.getVSVars(config.get("paths.visual_studio"), os.path.join("build", "getvsvars.bat"))

    for d in ["download", "build", "progress"]:
        if not os.path.exists(config["paths"][d]):
            os.makedirs(config["paths"][d])

    time_format = "%(asctime)-15s %(message)s"
    logging.basicConfig(format=time_format, level=logging.DEBUG)

    logging.debug("building dependency graph")
    manager = TaskManager()
    imp.load_source("build", args.file)
    build_graph = manager.create_graph({})
    assert isinstance(build_graph, nx.DiGraph)

    if args.graph:
        draw_graph(build_graph, "graph")

    cycles = list(nx.simple_cycles(build_graph))
    if cycles:
        logging.error("There are cycles in the build graph")
        for cycle in cycles:
            logging.info(", ".join(cycle))
        return 1

    if args.target:
        for target in args.target:
            manager.enable(build_graph, target)
    else:
        manager.enable_all(build_graph)

    logging.debug("processing tasks")
    independent = extract_independent(build_graph)

    while independent:
        for node in independent:
            task = build_graph.node[node]["task"]
            try:
                task.prepare()
                if build_graph.node[node]["enable"] and not task.already_processed():
                    progress = Progress()
                    progress.set_change_callback(progress_callback)
                    if isinstance(task, Project):
                        logging.debug('finished project "{}"'.format(node))
                    else:
                        logging.debug('run task "{}"'.format(node))
                    if task.process(progress):
                        task.mark_success()
                    else:
                        if task.fail_behaviour == Task.FailBehaviour.FAIL:
                            logging.critical("task %s failed", node)
                            return 1
                        elif task.fail_behaviour == Task.FailBehaviour.SKIP_PROJECT:
                            recursive_remove(build_graph, node)
                            break
                        elif task.fail_behaviour == Task.FailBehaviour.CONTINUE:
                            # nothing to do
                            pass
                    sys.stdout.write("\n")
            except Exception, e:
                logging.error("Task {} failed: {}".format(task.name, e))
                raise

            build_graph.remove_node(node)

        independent = extract_independent(build_graph)