Generates the license index and the static website at ``output_path``. ``environment`` is a jinja Environment object used to generate the webpage and ``licenses`` is a mapping with scancode license data.
(output_path, environment, licenses, test=False)
| 52 | |
| 53 | |
| 54 | def generate_indexes(output_path, environment, licenses, test=False): |
| 55 | """ |
| 56 | Generates the license index and the static website at ``output_path``. |
| 57 | |
| 58 | ``environment`` is a jinja Environment object used to generate the webpage |
| 59 | and ``licenses`` is a mapping with scancode license data. |
| 60 | """ |
| 61 | if test: |
| 62 | base_context_mapping = base_context_test |
| 63 | else: |
| 64 | base_context_mapping = base_context |
| 65 | static_dest_dir = join(output_path, 'static') |
| 66 | if not os.path.exists(static_dest_dir): |
| 67 | os.makedirs(static_dest_dir) |
| 68 | |
| 69 | copy_tree(STATIC_DIR, static_dest_dir) |
| 70 | |
| 71 | license_list_template = environment.get_template("license_list.html") |
| 72 | index_html = license_list_template.render( |
| 73 | **base_context_mapping, |
| 74 | licenses=licenses, |
| 75 | ) |
| 76 | write_file(output_path, "index.html", index_html) |
| 77 | |
| 78 | index = [ |
| 79 | { |
| 80 | "license_key": key, |
| 81 | "category": lic.category, |
| 82 | "spdx_license_key": lic.spdx_license_key, |
| 83 | "other_spdx_license_keys": lic.other_spdx_license_keys, |
| 84 | "is_exception": lic.is_exception, |
| 85 | "is_deprecated": lic.is_deprecated, |
| 86 | "json": f"{key}.json", |
| 87 | "yaml": f"{key}.yml", |
| 88 | "html": f"{key}.html", |
| 89 | "license": f"{key}.LICENSE", |
| 90 | } |
| 91 | for key, lic in licenses.items() |
| 92 | ] |
| 93 | |
| 94 | write_file( |
| 95 | output_path, |
| 96 | "index.json", |
| 97 | json.dumps(index, indent=2, sort_keys=False) |
| 98 | ) |
| 99 | write_file( |
| 100 | output_path, |
| 101 | "index.yml", |
| 102 | saneyaml.dump(index, indent=2) |
| 103 | ) |
| 104 | return len(index) |
| 105 | |
| 106 | |
| 107 | def generate_details(output_path, environment, licenses, test=False): |