Esempio n. 1
0
def copy_static(root_directory, dist_directory, sdk_directory, development):
    """
    Copy all static files from source to target.
    """

    for static in configuration.STATICS:
        context = {
            "development": development,
            "dist": dist_directory,
            "root": root_directory,
            "sdk": sdk_directory,
        }

        source = templates.from_string(static["source"], context)
        target = templates.from_string(static["target"], context)
        target = os.path.join(dist_directory, target)

        # Compute filters.
        ignored = []

        if "filters" in static:
            for expression in static["filters"].iterkeys():
                new_expression = templates.from_string(expression, context)

                if not static["filters"][expression](context):
                    ignored.append(new_expression)

        # Perform the action.
        sys.stdout.write("Copying '%s'\n" % source)

        if static["type"] == "directory":
            recursive_overwrite(source, target, ignored)
        else:
            if source not in ignored:
                shutil.copy(source, target)
Esempio n. 2
0
    def _process(when, contexts):
        for context in contexts:
            for template in configuration.TEMPLATES:
                if template["when"] == when:
                    context.update({
                        "development": development,
                        "dist": dist_directory,
                        "root": root_directory,
                        "sdk": sdk_directory,
                    })

                    source = templates.from_string(template["source"], context)
                    target = templates.from_string(template["target"], context)
                    target = os.path.join(dist_directory, target)

                    # Compute filters.
                    filters = {}

                    if "filters" in template:
                        for expression in template["filters"].iterkeys():
                            new_expression = templates.from_string(
                                expression, context)

                            filters[new_expression] = \
                                template["filters"][expression]

                    # Perform the action.
                    sys.stdout.write("Processing '%s'\n" % source)

                    if template["type"] == "file":
                        if source in filters:
                            if not filters[source](contexts):
                                continue

                        templates.from_file(source, target, context)
                    elif template["type"] == "glob":
                        for source_file in glob.glob(source):
                            if os.path.isfile(source_file):
                                if source_file in filters:
                                    if not filters[source_file](context):
                                        continue

                                target_file = os.path.join(
                                    target, os.path.basename(source_file))

                                templates.from_file(source_file, target_file,
                                                    context)
                    else:
                        raise Exception("Unsupported template: %s",
                                        template["type"])
Esempio n. 3
0
    def _process(when, contexts):
        for context in contexts:
            for template in configuration.TEMPLATES:
                if template["when"] == when:
                    context.update({
                        "development": development,
                        "dist": dist_directory,
                        "root": root_directory,
                        "sdk": sdk_directory,
                    })

                    source = templates.from_string(template["source"], context)
                    target = templates.from_string(template["target"], context)
                    target = os.path.join(dist_directory, target)

                    # Compute filters.
                    filters = {}

                    if "filters" in template:
                        for expression in template["filters"].iterkeys():
                            new_expression = templates.from_string(
                                expression, context)

                            filters[new_expression] = \
                                template["filters"][expression]

                    # Perform the action.
                    sys.stdout.write("Processing '%s'\n" % source)

                    if template["type"] == "file":
                        if source in filters:
                            if not filters[source](contexts):
                                continue

                        templates.from_file(source, target, context)
                    elif template["type"] == "glob":
                        for source_file in glob.glob(source):
                            if os.path.isfile(source_file):
                                if source_file in filters:
                                    if not filters[source_file](context):
                                        continue

                                target_file = os.path.join(
                                    target, os.path.basename(source_file))

                                templates.from_file(
                                    source_file, target_file, context)
                    else:
                        raise Exception(
                            "Unsupported template: %s", template["type"])
Esempio n. 4
0
    def _process(when, contexts):
        for context in contexts:
            for patch in configuration.PATCHES:
                if patch["when"] == when:
                    context.update({
                        "root": root_directory,
                        "sdk": sdk_directory,
                        "dist": dist_directory
                    })

                    source = templates.from_string(patch["source"], context)
                    target = templates.from_string(patch["target"], context)
                    target = os.path.join(dist_directory, target)

                    # Perform the action.
                    sys.stdout.write("Patching '%s'\n" % source)

                    if patch["type"] == "file":
                        with open(source, "r") as fp:
                            content = fp.read()

                        for method in patch["methods"]:
                            content = method(source, content)

                        if not os.path.isdir(target):
                            os.makedirs(target)

                        with open(target, "w") as fp:
                            fp.write(content)
                    elif patch["type"] == "glob":
                        for source_file in glob.glob(source):
                            if os.path.isfile(source_file):
                                target_file = os.path.join(
                                    target, os.path.basename(source_file))

                                with open(source_file, "r") as fp:
                                    content = fp.read()

                                for method in patch["methods"]:
                                    content = method(source, content)

                                if not os.path.isdir(target):
                                    os.makedirs(target)

                                with open(target_file, "w") as fp:
                                    fp.write(content)
                    else:
                        raise Exception("Not supported")
Esempio n. 5
0
    def _process(when, contexts):
        for context in contexts:
            for patch in configuration.PATCHES:
                if patch["when"] == when:
                    context.update({
                        "root": root_directory,
                        "sdk": sdk_directory,
                        "dist": dist_directory
                    })

                    source = templates.from_string(patch["source"], context)
                    target = templates.from_string(patch["target"], context)
                    target = os.path.join(dist_directory, target)

                    # Perform the action.
                    sys.stdout.write("Patching '%s'\n" % source)

                    if patch["type"] == "file":
                        with open(source, "r") as fp:
                            content = fp.read()

                        for method in patch["methods"]:
                            content = method(source, content)

                        with open(target, "w") as fp:
                            fp.write(content)
                    elif patch["type"] == "glob":
                        for source_file in glob.glob(source):
                            if os.path.isfile(source_file):
                                target_file = os.path.join(
                                    target, os.path.basename(source_file))

                                with open(source_file, "r") as fp:
                                    content = fp.read()

                                for method in patch["methods"]:
                                    content = method(source, content)

                                with open(target_file, "w") as fp:
                                    fp.write(content)
                    else:
                        raise Exception("Not supported")
Esempio n. 6
0
def copy_static(root_directory, dist_directory, sdk_directory, development):
    """
    Copy all static files from source to target.
    """

    for static in configuration.STATICS:
        context = {
            "development": development,
            "dist": dist_directory,
            "root": root_directory,
            "sdk": sdk_directory,
        }

        source = templates.from_string(static["source"], context)
        target = templates.from_string(static["target"], context)
        target = os.path.join(dist_directory, target)

        # Compute filters.
        ignored = []

        if "filters" in static:
            for expression in static["filters"].iterkeys():
                new_expression = templates.from_string(
                    expression, context)

                if not static["filters"][expression](context):
                    ignored.append(new_expression)

        # Perform the action.
        sys.stdout.write("Copying '%s'\n" % source)

        if static["type"] == "directory":
            recursive_overwrite(source, target, ignored)
        else:
            if source not in ignored:
                shutil.copy(source, target)