cookiecutter-ansible-role-d.../hooks/post_gen_project.py

45 lines
1.4 KiB
Python
Raw Permalink Normal View History

2020-04-28 13:23:10 +02:00
#!/usr/bin/python3
import sys
import os
import shutil
def checkInput():
appName = "{{ cookiecutter.app_name }}"
moleculeVersion = "{{ cookiecutter.molecule_version }}"
if appName.endswith("role"):
print("Error: app_name should not have _role or -role at the end, try again without it")
print(" The name of the role will the value you introduce in app_name plus _role appended")
sys.exit(1)
if not (moleculeVersion.startswith("3") or moleculeVersion.startswith("4")):
print("Error: Only supported molecule version 3.x.x or 4.x.x, please change it and try again")
2020-04-28 13:23:10 +02:00
sys.exit(1)
def configureRole():
# Remove or not the service
shutil.rmtree("molecule/default/group_vars")
# Remove or not the handlers folder
if not {{ cookiecutter.has_handlers }}:
shutil.rmtree("handlers")
# Remove or not the templates folder
if not {{ cookiecutter.has_templates }}:
shutil.rmtree("templates")
2020-04-28 13:23:10 +02:00
# Remove or not the files folder
if not {{ cookiecutter.has_files }}:
shutil.rmtree("files")
else:
os.remove("files/.empty")
def generatePipfile():
2020-10-06 14:08:19 +02:00
print("Now cd into the role directory and introduce the following command for it to be ready: \"pipenv install -r test-requirements.txt --three\"")
2020-04-28 13:23:10 +02:00
def main():
checkInput()
configureRole()
generatePipfile()
if __name__ == '__main__':
main()