diff --git a/cookiecutter.json b/cookiecutter.json index fe8f086..7787efd 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -1,6 +1,6 @@ { "new_wiki": "", - "wiki_name": "{{ cookiecutter.new_wiki|title|replace(' ', '')|replace('Wiki', '') }}", + "wiki_name": "{{ cookiecutter.new_wiki|title|replace(' ', '') }}", "directory_name": "{{ cookiecutter.wiki_name|lower }}", "url": "https://{{cookiecutter.directory_name}}.cpi.imtek.uni-freiburg.de/" } diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py new file mode 100644 index 0000000..d398a9f --- /dev/null +++ b/hooks/pre_gen_project.py @@ -0,0 +1,25 @@ +import re +import sys +from pathlib import Path + +MOIN_PATH = '/var/www/moin/wikis' +MODULE_REGEX = r'^[_a-zA-Z][_a-zA-Z0-9]+$' + +module_name = '{{ cookiecutter.directory_name }}' + +if not re.match(MODULE_REGEX, module_name): + print('ERROR: %s is not a valid Python module name!' % module_name) + sys.exit(1) + +try: + import {{ cookiecutter.directory_name }} + print('ERROR: %s is an existing Python module!' % module_name) + sys.exit(2) +except ModuleNotFoundError: + pass + + +wiki_path = Path(MOIN_PATH) / module_name +if wiki_path.exists(): + print('ERROR: wiki %s already exists!' % module_name) + sys.exit(1)