blob: 438b09e6b5310cce9a0812964d0724bce992e144 [file] [log] [blame]
Zack Williamsad45bf02020-03-04 21:37:20 -07001#!/usr/bin/env python3
2#
Zack Williamse58b0eb2022-03-19 21:23:49 -07003# SPDX-FileCopyrightText: 2020 Open Networking Foundation <support@opennetworking.org>
Zack Williamsad45bf02020-03-04 21:37:20 -07004# SPDX-License-Identifier: Apache-2.0
5
6# role/hooks/post_gen_project.py
7# Generates platform-specific files for ansible roles
8
9from __future__ import absolute_import
10import os
Zack Williamsad45bf02020-03-04 21:37:20 -070011
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
23PROJECT_DIR = os.path.realpath(os.path.join("..", os.path.curdir))
24
25# Hack, but 'cookiecutter._template' is a relative path
26TEMPLATE_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 Williamsdac2be42021-08-19 16:14:31 -070032CONTEXT = {{cookiecutter | jsonify}} # noqa: F821, E227 pylint: disable=E0602
Zack Williamsad45bf02020-03-04 21:37:20 -070033
34
35def delete_file(filepath):
Zack Williamse58b0eb2022-03-19 21:23:49 -070036 """delete generated file from output directory"""
Zack Williamsad45bf02020-03-04 21:37:20 -070037 os.remove(os.path.join(PROJECT_DIR, filepath))
38
39
Zack Williamsad45bf02020-03-04 21:37:20 -070040def 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 Williamsdac2be42021-08-19 16:14:31 -070048 if not licfile.startswith(CONTEXT["license"]): # pylint: disable=E1136
Zack Williamsad45bf02020-03-04 21:37:20 -070049 os.remove(os.path.join(os.path.curdir, "LICENSES", licfile))
50
51
52if __name__ == "__main__":
53
Zack Williamsad45bf02020-03-04 21:37:20 -070054 delete_inactive_licenses()