Module continuous_delivery_scripts.license_files
Apply copyright and licensing to all source files present in a project.
This is to comply with OpenChain certification; https://github.com/OpenChain-Project/Curriculum/blob/master/guides/reusing_software.md#2-include-a-copyright-notice-and-license-in-each-file
Functions
def add_licence_header(verbose_count: int, src: pathlib.Path) ‑> None-
Expand source code
def add_licence_header(verbose_count: int, src: Path) -> None: """Puts a copyright notice at the top of every source file. Wrapper over the [licenseheaders tool](https://github.com/johann-petrak/licenseheaders). """ # copyright (https://github.com/knipknap/copyright) was first considered but # comprises quite a few bugs and does not seem active anymore. if not get_language_specifics().can_add_licence_headers(): return template_string = get_language_specifics().generate_source_licence_header_template() with tempfile.NamedTemporaryFile(suffix=".tmpl", delete=False) as template_file: template_file_path = Path(template_file.name) logger.debug(f"Creates template file in {str(template_file_path)}") template_file.write(template_string.encode("utf8")) template_file.close() copyright_config = get_tool_config(template_file_path, src) _call_licensehearders(copyright_config, verbose_count)Puts a copyright notice at the top of every source file.
Wrapper over the licenseheaders tool.
def get_tool_config(template_file: pathlib.Path, src: pathlib.Path) ‑> dict-
Expand source code
def get_tool_config(template_file: Path, src: Path) -> dict: """Gets the configuration for licenseheaders.""" copyright_dates = _determines_copyright_dates() return { "owner": configuration.get_value(ConfigurationVariable.ORGANISATION), "dir": src, "projname": configuration.get_value(ConfigurationVariable.PROJECT_NAME), "tmpl": str(template_file), "years": copyright_dates, "additional-extensions": ADDITIONAL_EXTENSIONS, "exclude": FILES_TO_IGNORE, }Gets the configuration for licenseheaders.
def insert_licence_header(verbose_count: int) ‑> None-
Expand source code
def insert_licence_header(verbose_count: int) -> None: """Inserts a copyright notice at the top of every source file of the current project. Wrapper over the [licenseheaders tool](https://github.com/johann-petrak/licenseheaders). """ # copyright (https://github.com/knipknap/copyright) was first considered but # comprises quite a few bugs and does not seem active anymore. add_licence_header(verbose_count, Path(configuration.get_value(ConfigurationVariable.PROJECT_ROOT)))Inserts a copyright notice at the top of every source file of the current project.
Wrapper over the licenseheaders tool.
def main() ‑> int-
Expand source code
def main() -> int: """Creates a CLI.""" parser = argparse.ArgumentParser(description="Adds licence header to every source file of a project.") parser.add_argument("-v", "--verbose", action="count", default=0, help="Verbosity, by default errors are reported.") args = parser.parse_args() set_log_level(args.verbose) try: insert_licence_header(args.verbose) except Exception as e: log_exception(logger, e) return 1 return 0Creates a CLI.