mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-08 14:04:52 +03:00
Fix ./hooks/pre_gen_project.py asking user to select an option once only
+ prettify output
This commit is contained in:
parent
1148802655
commit
ee8a5c2692
|
@ -1,27 +1,50 @@
|
|||
project_slug = '{{ cookiecutter.project_slug }}'
|
||||
|
||||
if hasattr(project_slug, 'isidentifier'):
|
||||
assert project_slug.isidentifier(), 'Project slug should be valid Python identifier!'
|
||||
assert project_slug.isidentifier(), "'{}' project slug is not a valid Python identifier.".format(project_slug)
|
||||
|
||||
heroku = '{{ cookiecutter.use_heroku }}'.lower()
|
||||
docker = '{{ cookiecutter.use_docker }}'.lower()
|
||||
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]: "
|
||||
|
||||
if docker == 'n':
|
||||
import sys
|
||||
|
||||
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.4+ only. Are you sure you want to proceed? (y/n)")
|
||||
|
||||
yes_options = set(['y'])
|
||||
no_options = set(['n', ''])
|
||||
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 no_options:
|
||||
sys.exit(1)
|
||||
elif choice in yes_options:
|
||||
pass
|
||||
if choice in yes_options:
|
||||
break
|
||||
elif choice in no_options:
|
||||
sys.stdout.write(
|
||||
INFO +
|
||||
"Generation process stopped as requested." +
|
||||
TERMINATOR
|
||||
)
|
||||
sys.exit(0)
|
||||
else:
|
||||
sys.stdout.write("Please respond with %s or %s"
|
||||
% (', '.join([o for o in yes_options if not o == ''])
|
||||
, ', '.join([o for o in no_options if not o == ''])))
|
||||
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
|
||||
)
|
||||
|
||||
sys.stdout.write(
|
||||
SUCCESS +
|
||||
"Project initialized, keep up the good work!" +
|
||||
TERMINATOR
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user