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
|
|
|
|
2021-11-26 18:41:50 +03:00
|
|
|
TODO: restrict Cookiecutter Django project initialization
|
|
|
|
to Python 3.x environments only
|
2018-02-07 22:52:52 +03:00
|
|
|
"""
|
2024-01-26 13:49:52 +03:00
|
|
|
|
2018-03-08 15:56:15 +03:00
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
TERMINATOR = "\x1b[0m"
|
|
|
|
WARNING = "\x1b[1;33m [WARNING]: "
|
|
|
|
INFO = "\x1b[1;33m [INFO]: "
|
|
|
|
HINT = "\x1b[3;33m"
|
|
|
|
SUCCESS = "\x1b[1;32m [SUCCESS]: "
|
2016-04-26 00:09:37 +03:00
|
|
|
|
2023-03-16 20:17:02 +03:00
|
|
|
# The content of this string is evaluated by Jinja, and plays an important role.
|
|
|
|
# It updates the cookiecutter context to trim leading and trailing spaces
|
|
|
|
# from domain/email values
|
|
|
|
"""
|
|
|
|
{{ cookiecutter.update({ "domain_name": cookiecutter.domain_name | trim }) }}
|
|
|
|
{{ cookiecutter.update({ "email": cookiecutter.email | trim }) }}
|
|
|
|
"""
|
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
project_slug = "{{ cookiecutter.project_slug }}"
|
|
|
|
if hasattr(project_slug, "isidentifier"):
|
2023-04-15 17:43:04 +03:00
|
|
|
assert project_slug.isidentifier(), "'{}' project slug is not a valid Python identifier.".format(project_slug)
|
2016-06-04 02:35:10 +03:00
|
|
|
|
2023-04-15 17:43:04 +03:00
|
|
|
assert project_slug == project_slug.lower(), "'{}' project slug should be all lowercase".format(project_slug)
|
2019-06-05 21:00:43 +03:00
|
|
|
|
2023-04-15 17:43:04 +03:00
|
|
|
assert "\\" not in "{{ cookiecutter.author_name }}", "Don't include backslashes in author name."
|
2018-02-22 02:54:03 +03:00
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
if "{{ cookiecutter.use_docker }}".lower() == "n":
|
2018-02-07 22:52:52 +03:00
|
|
|
python_major_version = sys.version_info[0]
|
|
|
|
if python_major_version == 2:
|
2018-03-08 15:56:15 +03:00
|
|
|
print(
|
2019-03-28 00:27:52 +03:00
|
|
|
WARNING + "You're running cookiecutter under Python 2, but the generated "
|
2023-04-15 13:42:33 +03:00
|
|
|
"project requires Python 3.11+. Do you want to proceed (y/n)? " + TERMINATOR
|
2018-02-07 22:52:52 +03:00
|
|
|
)
|
2018-04-09 01:03:29 +03:00
|
|
|
yes_options, no_options = frozenset(["y"]), frozenset(["n"])
|
2018-02-07 22:52:52 +03:00
|
|
|
while True:
|
2021-11-26 18:41:50 +03:00
|
|
|
choice = raw_input().lower() # noqa: F821
|
2018-02-07 22:52:52 +03:00
|
|
|
if choice in yes_options:
|
|
|
|
break
|
2018-04-09 01:03:29 +03:00
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
elif choice in no_options:
|
2018-04-09 01:03:29 +03:00
|
|
|
print(INFO + "Generation process stopped as requested." + TERMINATOR)
|
2018-02-07 22:52:52 +03:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2018-03-08 15:56:15 +03:00
|
|
|
print(
|
2018-04-09 01:03:29 +03:00
|
|
|
HINT
|
|
|
|
+ "Please respond with {} or {}: ".format(
|
2023-04-15 17:43:04 +03:00
|
|
|
", ".join(["'{}'".format(o) for o in yes_options if not o == ""]),
|
|
|
|
", ".join(["'{}'".format(o) for o in no_options if not o == ""]),
|
2018-04-09 01:03:29 +03:00
|
|
|
)
|
|
|
|
+ TERMINATOR
|
2018-02-07 22:52:52 +03:00
|
|
|
)
|
2019-10-02 18:03:33 +03:00
|
|
|
|
2023-04-15 17:43:04 +03:00
|
|
|
if "{{ cookiecutter.use_whitenoise }}".lower() == "n" and "{{ cookiecutter.cloud_provider }}" == "None":
|
|
|
|
print("You should either use Whitenoise or select a " "Cloud Provider to serve static files")
|
2019-10-02 18:03:33 +03:00
|
|
|
sys.exit(1)
|
2020-03-22 20:31:52 +03:00
|
|
|
|
2023-04-15 17:43:04 +03:00
|
|
|
if "{{ cookiecutter.mail_service }}" == "Amazon SES" and "{{ cookiecutter.cloud_provider }}" != "AWS":
|
|
|
|
print("You should either use AWS or select a different " "Mail Service for sending emails.")
|
2020-03-22 20:31:52 +03:00
|
|
|
sys.exit(1)
|