#!/usr/bin/env python

import os
from distutils.dir_util import copy_tree, remove_tree
import sys  # TODO: replace with argparser

import eve_utils

project_name = sys.argv[1]  # TODO: ensure valid dir name, no spaces, other safety considerations
print(f'Creating docker files for {project_name}')

skel = os.path.join(os.path.dirname(eve_utils.__file__), 'skel/docker')

if not os.path.exists(f'{project_name}'):
    print(f'Please run this in the folder above {project_name}')
else:
    copy_tree(skel, '.')

    # TODO: potentially dangerous to traverse folder from here?
    for dname, dirs, files in os.walk('.'):
        for fname in files:
            fpath = os.path.join(dname, fname)
            with open(fpath) as f:
                s = f.read()
            s = s.replace("{$project_name}", project_name)
            with open(fpath, "w") as f:
                f.write(s)

