コード例 #1
0
def generate_reports_by_base(data, output):
    log("Generating reports: Bases with use cases")

    template_loader = jinja2.FileSystemLoader(searchpath="./templates/")
    template_env = jinja2.Environment(loader=template_loader)

    for _, base in data["bases"].items():
        base_report_data = {
            "name": base["name"],
            "version": base["version"],
            "size": showme.size(base["total_size"]),
            "packages": base["package_names"],
            "file_id": base["file_id"]
        }

        other_install_data = []
        for use_case_id in base["use_case_ids"]:
            use_case = data["use_cases"][use_case_id]

            use_case_report_data = {
                "name": use_case["name"],
                "size": showme.size(use_case["total_size"]),
                "pkgs_in_base": use_case["packages_in_base"],
                "pkgs_not_in_base": use_case["packages_not_in_base"],
                "required_pkgs": use_case["required_package_names"],
                "packages": use_case["packages"],
                "file_id": use_case["file_id"]
            }

            other_install_data.append(use_case_report_data)

        extra_pkgs = []
        for install_data in other_install_data:
            extra_pkgs += install_data["pkgs_not_in_base"]
        extra_pkgs = list(set(extra_pkgs))
        extra_pkgs.sort()

        table_report_template = template_env.get_template(
            "report_by_base.html")
        table_report = table_report_template.render(base=base_report_data,
                                                    images=other_install_data,
                                                    extra_pkgs=extra_pkgs)

        filename = "report-by-base--{file_id}.html".format(
            file_id=base["file_id"])

        with open(os.path.join(output, filename), "w") as file:
            file.write(table_report)
コード例 #2
0
def generate_reports_bases_releases(data, output):
    log("Generating reports: Bases by releases")

    template_loader = jinja2.FileSystemLoader(searchpath="./templates/")
    template_env = jinja2.Environment(loader=template_loader)

    for _, base_definition in data["base_definitions"].items():
        report_data = []
        for base_version in base_definition["versions"]:
            base_id = "{base_definition_id}:{base_version}".format(
                base_definition_id=base_definition["id"],
                base_version=base_version)
            base = data["bases"][base_id]

            base_report_data = {
                "version": base_version,
                "size": showme.size(base["total_size"]),
                "required_pkgs": base["required_package_names"],
                "packages": base["packages"],
                "file_id": base["file_id"]
            }
            report_data.append(base_report_data)

        all_packages = []
        for base_report_data in report_data:
            all_packages += base_report_data["packages"].keys()
        all_packages = list(set(all_packages))
        all_packages.sort()

        table_report_template = template_env.get_template(
            "report_base_releases.html")
        table_report = table_report_template.render(
            report_data=report_data,
            all_packages=all_packages,
            base_name=base_definition["name"],
            size_function=showme.size,
            timestamp=data["timestamp"])

        filename = "report-base-releases--{base_id}.html".format(
            base_id=base_definition["id"])

        with open(os.path.join(output, filename), "w") as file:
            file.write(table_report)
コード例 #3
0
def generate_reports_by_use_case(data, output):
    log("Generating reports: Use cases on bases")

    template_loader = jinja2.FileSystemLoader(searchpath="./templates/")
    template_env = jinja2.Environment(loader=template_loader)

    for use_case_definition in data["use_case_definitions"]:
        for base_version in use_case_definition["base_versions"]:
            use_case_report_data = {
                "name": use_case_definition["name"],
                "packages": use_case_definition["packages"],
                "version": base_version
            }

            other_install_data = []
            for base_definition_id in use_case_definition["base_ids"]:
                base_id = "{base_definition_id}:{base_version}".format(
                    base_definition_id=base_definition_id,
                    base_version=base_version)
                use_case_id = "{use_case_definition_id}:{base_id}".format(
                    use_case_definition_id=use_case_definition["id"],
                    base_id=base_id)

                base = data["bases"][base_id]
                use_case = data["use_cases"][use_case_id]

                required_package_names = use_case["required_package_names"]
                all_package_names = use_case["package_names"]
                dependencies = list(
                    set(all_package_names) - set(required_package_names))
                dependencies.sort()

                base_report_data = {
                    "name": base["name"],
                    "size": showme.size(use_case["total_size"]),
                    "required_pkgs": required_package_names,
                    "dependencies": dependencies,
                    "packages": use_case["packages"],
                    "file_id": use_case["file_id"]
                }
                other_install_data.append(base_report_data)

            extra_pkgs = []
            for install_data in other_install_data:
                extra_pkgs += install_data["dependencies"]
            extra_pkgs = list(set(extra_pkgs))
            extra_pkgs.sort()

            table_report_template = template_env.get_template(
                "report_by_use_case.html")
            table_report = table_report_template.render(
                base=use_case_report_data,
                images=other_install_data,
                extra_pkgs=extra_pkgs)

            file_id = "{use_case}--{version}".format(
                use_case=use_case_definition["id"], version=base_version)
            filename = "report-by-use-case--{file_id}.html".format(
                file_id=file_id)

            with open(os.path.join(output, filename), "w") as file:
                file.write(table_report)
コード例 #4
0
def generate_reports_by_base(data, output):
    log("Generating reports: Bases with use cases")

    template_loader = jinja2.FileSystemLoader(searchpath="./templates/")
    template_env = jinja2.Environment(loader=template_loader)

    for _, base in data["bases"].items():
        base_report_data = {
            "name": base["name"],
            "version": base["version"],
            "size": showme.size(base["total_size"]),
            "packages": base["package_names"],
            "file_id": base["file_id"]
        }

        pkg_sizes = {}
        pkg_sizes_num = {}

        # Get sizes of all packags in the base
        for _, pkg in base["packages"].items():
            if pkg["name"] not in pkg_sizes:
                pkg_sizes[pkg["name"]] = showme.size(pkg["size"])
                pkg_sizes_num[pkg["name"]] = pkg["size"]

        use_case_data = []
        for use_case_id in base["use_case_ids"]:
            use_case = data["use_cases"][use_case_id]

            # Get sizes of all other packages
            for _, pkg in use_case["packages"].items():
                if pkg["name"] not in pkg_sizes:
                    pkg_sizes[pkg["name"]] = showme.size(pkg["size"])
                    pkg_sizes_num[pkg["name"]] = pkg["size"]

            use_case_report_data = {
                "name": use_case["name"],
                "definition_id": use_case["definition_id"],
                "size": showme.size(use_case["total_size"]),
                "pkgs_in_base": use_case["packages_in_base"],
                "pkgs_not_in_base": use_case["packages_not_in_base"],
                "required_pkgs": use_case["required_package_names"],
                "packages": use_case["packages"],
                "file_id": use_case["file_id"]
            }

            use_case_data.append(use_case_report_data)

        # Sort use cases by name
        use_case_data_sorted = sorted(use_case_data, key=lambda k: k["name"])

        extra_pkgs = []
        for install_data in use_case_data_sorted:
            extra_pkgs += install_data["pkgs_not_in_base"]
        extra_pkgs = list(set(extra_pkgs))
        extra_pkgs.sort()

        table_report_template = template_env.get_template(
            "report_by_base.html")
        table_report = table_report_template.render(
            base=base_report_data,
            images=use_case_data_sorted,
            extra_pkgs=extra_pkgs,
            pkg_sizes=pkg_sizes,
            pkg_sizes_num=pkg_sizes_num,
            timestamp=data["timestamp"])

        filename = "report-by-base--{file_id}.html".format(
            file_id=base["file_id"])

        with open(os.path.join(output, filename), "w") as file:
            file.write(table_report)