This repository has been archived on 2020-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
magic-app/magic_app/templates.py

30 lines
766 B
Python

"""Compose template handling."""
from os import mkdir
from os.path import exists
from shlex import split
from shutil import rmtree
from subprocess import run
from flask import current_app
APP_TEMPLATES = {
"gitea": "https://git.autonomic.zone/compose-stacks/gitea",
}
def create_data_dir() -> None:
"""Create data directory for compose templates."""
try:
mkdir(current_app.config["DATA_DIR"])
except FileExistsError:
pass
def clone_app_template(app_name: str) -> None:
"""Clone an application template repository."""
clone_path = current_app.config["DATA_DIR"] / app_name
clone_url = APP_TEMPLATES[app_name]
if exists(clone_path):
rmtree(clone_path)
run(split(f"git clone {clone_url} {clone_path}"))