Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Zack Williams | e58b0eb | 2022-03-19 21:23:49 -0700 | [diff] [blame^] | 3 | # SPDX-FileCopyrightText: 2020 Open Networking Foundation <support@opennetworking.org> |
Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
| 6 | # role/hooks/post_gen_project.py |
| 7 | # Generates platform-specific files for ansible roles |
| 8 | |
| 9 | from __future__ import absolute_import |
| 10 | import os |
Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 11 | |
| 12 | # Docs for hooks |
| 13 | # https://cookiecutter.readthedocs.io/en/latest/advanced/hooks.html |
| 14 | |
| 15 | # Tickets related to what thei above |
| 16 | # https://github.com/cookiecutter/cookiecutter/issues/474 |
| 17 | # https://github.com/cookiecutter/cookiecutter/issues/851 |
| 18 | |
| 19 | # other implementations |
| 20 | # https://github.com/ckan/ckan/blob/master/contrib/cookiecutter/ckan_extension/hooks/post_gen_project.py |
| 21 | |
| 22 | # CWD is output dir |
| 23 | PROJECT_DIR = os.path.realpath(os.path.join("..", os.path.curdir)) |
| 24 | |
| 25 | # Hack, but 'cookiecutter._template' is a relative path |
| 26 | TEMPLATE_DIR = os.path.realpath( |
| 27 | os.path.join(os.path.curdir, "../{{ cookiecutter._template }}") |
| 28 | ) |
| 29 | |
| 30 | # script is rendered as a template, so this will be filled in with the |
| 31 | # cookiecutter dict, which is why noqa is needed. |
Zack Williams | dac2be4 | 2021-08-19 16:14:31 -0700 | [diff] [blame] | 32 | CONTEXT = {{cookiecutter | jsonify}} # noqa: F821, E227 pylint: disable=E0602 |
Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 33 | |
| 34 | |
| 35 | def delete_file(filepath): |
Zack Williams | e58b0eb | 2022-03-19 21:23:49 -0700 | [diff] [blame^] | 36 | """delete generated file from output directory""" |
Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 37 | os.remove(os.path.join(PROJECT_DIR, filepath)) |
| 38 | |
| 39 | |
Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 40 | def delete_inactive_licenses(): |
| 41 | |
| 42 | # get list of licenses written to output |
| 43 | license_dir = os.path.join(os.path.curdir, "LICENSES") |
| 44 | license_files = os.listdir(license_dir) |
| 45 | |
| 46 | # delete any files that don't start with the license identifier |
| 47 | for licfile in license_files: |
Zack Williams | dac2be4 | 2021-08-19 16:14:31 -0700 | [diff] [blame] | 48 | if not licfile.startswith(CONTEXT["license"]): # pylint: disable=E1136 |
Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 49 | os.remove(os.path.join(os.path.curdir, "LICENSES", licfile)) |
| 50 | |
| 51 | |
| 52 | if __name__ == "__main__": |
| 53 | |
Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 54 | delete_inactive_licenses() |