Initial commit
This commit is contained in:
44
docker-compose/hooks/post_gen_project.py
Normal file
44
docker-compose/hooks/post_gen_project.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#print("{% set components = cookiecutter.component_s.split(',') -%}
|
||||
#{% for component in components -%}
|
||||
# {{ component }}
|
||||
# {%- if not loop.last -%}
|
||||
# ,
|
||||
# {%- endif %}
|
||||
#{%- endfor %}")
|
||||
import os
|
||||
import sys
|
||||
|
||||
component_subdirs = ["extras", "docker-data"]
|
||||
components = ["grafana", "nginx"]
|
||||
project_dir = os.getcwd()
|
||||
build_context_dir_name = "build-context"
|
||||
build_ctx_dir_abs = os.path.join(project_dir, build_context_dir_name)
|
||||
for component in components:
|
||||
component_dir_abs = os.path.join(build_ctx_dir_abs, component)
|
||||
component_dir_rel = os.path.relpath(component_dir_abs, project_dir)
|
||||
try:
|
||||
os.mkdir(component_dir_abs)
|
||||
except FileExistsError:
|
||||
print(f"Dir './{component_dir_rel}' already exists when it shouldn't. Aborting and exiting 1 ...")
|
||||
sys.exit(1)
|
||||
for component_subdir_name in component_subdirs:
|
||||
component_subdir_abs = os.path.join(component_dir_abs, component_subdir_name)
|
||||
try:
|
||||
os.mkdir(component_subdir_abs)
|
||||
except FileExistsError:
|
||||
print(f"Dir '{component_subdir_name}' inside './{component_dir_rel}' exists when it shouldn't. "
|
||||
f"Aborting and exiting 1 ...")
|
||||
sys.exit(1)
|
||||
|
||||
for root, subdirs, filelist in os.walk(project_dir):
|
||||
for subdir_name in subdirs:
|
||||
if subdir_name in component_subdirs:
|
||||
subdir_abs = os.path.join(root, subdir_name)
|
||||
gitkeep_file_abs = os.path.join(subdir_abs, ".gitkeep")
|
||||
gitkeep_file_rel = os.path.relpath(gitkeep_file_abs, project_dir)
|
||||
try:
|
||||
with open(gitkeep_file_abs, mode='a'):
|
||||
pass
|
||||
except IOError:
|
||||
print(f"Can't write './{gitkeep_file_rel}'. Aborting and exiting 2 ...")
|
||||
sys.exit(2)
|
Reference in New Issue
Block a user