Skip to content

Commit

Permalink
feat(post_gen_project): add support for vtk if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
devang-chauhan committed Jun 9, 2022
1 parent a57475c commit 0ae0e81
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pollination_apps/template/assets/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
"""This module performs post-generation tasks once the project is created.
These tasks may include: removing files, renaming files, etc.
"""

import os
import shutil
from pathlib import Path

# Remove .github folder if CI is not requested
REMOVE_PATHS = [
'{% if cookiecutter.ci != "github-actions" %} .github {% endif %}',
]


for path in REMOVE_PATHS:
path = path.strip()
if path and os.path.exists(path):
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.unlink(path)


# If Pollination_viewer is requested, add support for vtk in the Dockerfile
NEEDS_VIEWER = '{% if cookiecutter.pollination_viewer == "yes" %} yes {% endif %}'
if NEEDS_VIEWER.strip() == 'yes':
docker_file_path = Path('./app/Dockerfile')
with open(docker_file_path, 'r') as f:
docker_file_data = f.readlines()

vtk_support = [
'RUN apt-get update \\ \n',
'\t&& apt-get -y install ffmpeg libsm6 libxext6 xvfb --no-install-recommends \\ \n',
'\t&& apt-get clean \\ \n',
'\t&& rm -rf /var/lib/apt/lists/* \n',
'\n',
]

new_docker_file_data = docker_file_data[0:2] + vtk_support + docker_file_data[2:]
with open(docker_file_path, 'w') as f:
f.writelines(new_docker_file_data)

0 comments on commit 0ae0e81

Please sign in to comment.