2018-02-07 22:52:52 +03:00
|
|
|
"""
|
|
|
|
NOTE:
|
|
|
|
the below code is to be maintained Python 2.x-compatible
|
|
|
|
as the whole Cookiecutter Django project initialization
|
|
|
|
can potentially be run in Python 2.x environment.
|
2016-03-06 13:05:24 +03:00
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
TODO: ? restrict Cookiecutter Django project initialization to Python 3.x environments only
|
|
|
|
"""
|
2016-04-26 00:09:37 +03:00
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
project_slug = '{{ cookiecutter.project_slug }}'
|
|
|
|
if hasattr(project_slug, 'isidentifier'):
|
|
|
|
assert project_slug.isidentifier(), "'{}' project slug is not a valid Python identifier.".format(project_slug)
|
2016-06-04 02:35:10 +03:00
|
|
|
|
2018-02-22 02:54:03 +03:00
|
|
|
assert "\\" not in "{{ cookiecutter.author_name }}", "Don't include backslashes in author name."
|
|
|
|
|
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
using_docker = '{{ cookiecutter.use_docker }}'.lower()
|
|
|
|
if using_docker == 'n':
|
|
|
|
TERMINATOR = "\x1b[0m"
|
|
|
|
WARNING = "\x1b[1;33m [WARNING]: "
|
|
|
|
INFO = "\x1b[1;33m [INFO]: "
|
|
|
|
HINT = "\x1b[3;33m"
|
|
|
|
SUCCESS = "\x1b[1;32m [SUCCESS]: "
|
2017-04-25 01:43:36 +03:00
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
import sys
|
2017-04-25 01:43:36 +03:00
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
python_major_version = sys.version_info[0]
|
|
|
|
if python_major_version == 2:
|
|
|
|
sys.stdout.write(
|
|
|
|
WARNING +
|
|
|
|
"Cookiecutter Django does not support Python 2. "
|
|
|
|
"Stability is guaranteed with Python 3.6+ only, "
|
|
|
|
"are you sure you want to proceed (y/n)? " +
|
|
|
|
TERMINATOR
|
|
|
|
)
|
|
|
|
yes_options, no_options = frozenset(['y']), frozenset(['n'])
|
|
|
|
while True:
|
|
|
|
choice = raw_input().lower()
|
|
|
|
if choice in yes_options:
|
|
|
|
break
|
|
|
|
elif choice in no_options:
|
|
|
|
sys.stdout.write(
|
|
|
|
INFO +
|
|
|
|
"Generation process stopped as requested." +
|
|
|
|
TERMINATOR
|
|
|
|
)
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
sys.stdout.write(
|
|
|
|
HINT +
|
|
|
|
"Please respond with {} or {}: ".format(
|
|
|
|
', '.join(["'{}'".format(o) for o in yes_options if not o == '']),
|
|
|
|
', '.join(["'{}'".format(o) for o in no_options if not o == ''])
|
|
|
|
) +
|
|
|
|
TERMINATOR
|
|
|
|
)
|
2017-04-25 01:43:36 +03:00
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
sys.stdout.write(
|
|
|
|
SUCCESS +
|
|
|
|
"Project initialized, keep up the good work!" +
|
|
|
|
TERMINATOR
|
|
|
|
)
|