Jason M. Bills | 5905d41 | 2021-10-21 09:10:45 -0700 | [diff] [blame] | 1 | #### |
| 2 | # Copyright 2021 Intel Corporation |
| 3 | # |
| 4 | # Add a class to support serving license info through bmcweb. |
| 5 | # |
| 6 | # bmcweb serves static content from the /usr/share/www folder, so this class |
| 7 | # copies the license info from /usr/share/common-licenses to |
| 8 | # /usr/share/www/common-licenses so it will be statically served by bmcweb. |
| 9 | # |
| 10 | # Requires 'COPY_LIC_DIRS' to be enabled to create /usr/share/common-licenses. |
| 11 | # |
| 12 | # Class can be inherited in a project bbclass to copy the license info. |
| 13 | # |
| 14 | # Example: |
| 15 | # inherit license_static |
| 16 | #### |
| 17 | |
| 18 | STATIC_LICENSE_DIR = "${IMAGE_ROOTFS}/usr/share/www/common-licenses" |
| 19 | |
| 20 | |
| 21 | def add_index_html_header(f): |
| 22 | f.write("<!DOCTYPE html>") |
| 23 | f.write("<html>") |
| 24 | f.write("<body>") |
| 25 | f.write("<p>") |
| 26 | |
| 27 | |
| 28 | def add_index_html_footer(f): |
| 29 | f.write("</p>") |
| 30 | f.write("</body>") |
| 31 | f.write("</html>") |
| 32 | |
| 33 | |
| 34 | def create_index_files(d): |
| 35 | import os |
| 36 | |
| 37 | static_license_dir = d.getVar('STATIC_LICENSE_DIR') |
| 38 | for dirpath, dirnames, filenames in os.walk(static_license_dir): |
| 39 | with open(os.path.join(dirpath, "index.html"), "w") as f: |
| 40 | add_index_html_header(f) |
| 41 | full_list = filenames+dirnames |
| 42 | full_list.sort() |
| 43 | f.write("<br>".join(full_list)) |
| 44 | add_index_html_footer(f) |
| 45 | |
| 46 | |
| 47 | def copy_license_files(d): |
| 48 | import shutil |
| 49 | |
| 50 | rootfs_license_dir = d.getVar('ROOTFS_LICENSE_DIR') |
| 51 | static_license_dir = d.getVar('STATIC_LICENSE_DIR') |
| 52 | shutil.copytree(rootfs_license_dir, static_license_dir) |
| 53 | |
| 54 | |
| 55 | python do_populate_static_lic() { |
| 56 | copy_lic_dirs = d.getVar('COPY_LIC_DIRS') |
| 57 | if copy_lic_dirs == "1": |
| 58 | copy_license_files(d) |
| 59 | create_index_files(d) |
| 60 | else: |
| 61 | bb.warn("Static licenses not copied because 'COPY_LIC_DIRS' is disabled.") |
| 62 | } |
| 63 | |
| 64 | ROOTFS_POSTPROCESS_COMMAND:append = "do_populate_static_lic; " |