Browse Source

added pre_gen hook with additional checks

master
Holger Frey 7 years ago
parent
commit
6cc9211390
  1. 2
      cookiecutter.json
  2. 25
      hooks/pre_gen_project.py

2
cookiecutter.json

@ -1,6 +1,6 @@ @@ -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/"
}

25
hooks/pre_gen_project.py

@ -0,0 +1,25 @@ @@ -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)
Loading…
Cancel
Save