Esempio n. 1
0
 def depend(self, task):
     if isinstance(task, str):
         task_obj = TaskManager().get_task(task)
         if task_obj is None:
             raise KeyError("unknown project \"{}\"".format(task))
         else:
             task = task_obj
     else:
         task.set_context(self)
     return super(Project, self).depend(task)
Esempio n. 2
0
    def depend(self, task):
        """
        add a task as a dependency of this one. This means that the dependent task has to be fulfilled
        before this one will be processed.
        The order in which dependencies are fulfilled is arbitrary however, you can not control which
        of two sibling Tasks is processed first. This is because independent tasks could be processed
        asynchronously and they may be also be dependencies for a third task.
        """
        if isinstance(task, str):
            task_obj = TaskManager().get_task(task)
            if task_obj is None:
                raise KeyError("unknown project \"{}\"".format(task))
            else:
                task = task_obj
        else:
            if self._context:
                task.set_context(self._context)

        self.__dependencies.append(task)
        return self
Esempio n. 3
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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)
def GenerateFiles(path, data, c=1):
    for i in glob(os.path.join(path, "*")):
        if os.path.isfile(i):
            filepath, filename = os.path.split(i)
            if filename.endswith(".ts"):
                dest_dir = os.path.join(install_path, "bin", "translations")

                # filepath is the directory that contains the .ts file
                # in build/transifex-translations/translations, created
                # by the transifex tool when pulling the translations
                #
                # for example, 'mod-organizer-2.game_enderal'

                # filename is the name of the .ts file inside that
                # directory
                #
                # for example, 'de.ts'

                # the part after the dot, such as 'game_enderal'
                project = os.path.basename(filepath).split(".")[-1]

                # the name of the file without the extension, such as
                # 'de'
                lang = os.path.splitext(filename)[0]

                # the filename of the qm file, such as
                # 'game_enderal_de.qm'
                qm = project + "_" + lang + ".qm"

                src = os.path.join(filepath, filename)
                srcs = [src]
                dest = os.path.join(dest_dir, qm)

                # if the task depends on gamebryo, add its .ts file
                # so it gets merged with the one from this task
                t = TaskManager().get_task("modorganizer-" + project)

                if t is None:
                    # there's are case differences for some projects
                    t = TaskManager().get_task("modorganizer-" +
                                               project.lower())

                if t is not None:
                    if t.depends_on("modorganizer-game_gamebryo"):
                        translations = os.path.join(build_path,
                                                    "transifex-translations",
                                                    "translations")
                        gamebryo_dir = os.path.join(
                            translations, "mod-organizer-2.game_gamebryo")
                        gamebryo_ts = os.path.join(gamebryo_dir, filename)

                        # some translations might be missing
                        if os.path.exists(gamebryo_ts):
                            srcs.append(gamebryo_ts)

                data.update({dest: srcs})
        elif os.path.isdir(i):
            c += 1
            GenerateFiles(i, data, c)
            c -= 1
    return data