2015-09-10 03:56:27 +03:00
|
|
|
"""
|
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
|
|
|
|
(at least so we presume in `pre_gen_project.py`).
|
2015-09-15 04:55:41 +03:00
|
|
|
|
2021-11-26 18:41:50 +03:00
|
|
|
TODO: restrict Cookiecutter Django project initialization to
|
|
|
|
Python 3.x environments only
|
2015-09-10 03:56:27 +03:00
|
|
|
"""
|
2018-03-08 15:56:15 +03:00
|
|
|
from __future__ import print_function
|
2018-02-07 22:52:52 +03:00
|
|
|
|
2023-01-29 15:12:12 +03:00
|
|
|
import json
|
2015-09-10 03:56:27 +03:00
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import shutil
|
2017-02-14 02:37:14 +03:00
|
|
|
import string
|
2015-09-10 03:56:27 +03:00
|
|
|
|
|
|
|
try:
|
2018-02-07 22:52:52 +03:00
|
|
|
# Inspired by
|
|
|
|
# https://github.com/django/django/blob/master/django/utils/crypto.py
|
2015-09-10 03:56:27 +03:00
|
|
|
random = random.SystemRandom()
|
|
|
|
using_sysrandom = True
|
|
|
|
except NotImplementedError:
|
|
|
|
using_sysrandom = False
|
|
|
|
|
2018-03-08 15:56:15 +03:00
|
|
|
TERMINATOR = "\x1b[0m"
|
|
|
|
WARNING = "\x1b[1;33m [WARNING]: "
|
|
|
|
INFO = "\x1b[1;33m [INFO]: "
|
|
|
|
HINT = "\x1b[3;33m"
|
|
|
|
SUCCESS = "\x1b[1;32m [SUCCESS]: "
|
2016-04-08 10:45:09 +03:00
|
|
|
|
2018-05-05 13:47:58 +03:00
|
|
|
DEBUG_VALUE = "debug"
|
|
|
|
|
2016-04-08 10:45:09 +03:00
|
|
|
|
2018-03-08 15:56:15 +03:00
|
|
|
def remove_open_source_files():
|
2019-03-18 20:49:43 +03:00
|
|
|
file_names = ["CONTRIBUTORS.txt", "LICENSE"]
|
2018-02-07 22:52:52 +03:00
|
|
|
for file_name in file_names:
|
2018-03-08 15:56:15 +03:00
|
|
|
os.remove(file_name)
|
2015-10-15 19:29:43 +03:00
|
|
|
|
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
def remove_gplv3_files():
|
2018-04-09 01:03:29 +03:00
|
|
|
file_names = ["COPYING"]
|
2018-02-07 22:52:52 +03:00
|
|
|
for file_name in file_names:
|
2018-03-08 15:56:15 +03:00
|
|
|
os.remove(file_name)
|
2015-10-15 19:29:43 +03:00
|
|
|
|
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
def remove_pycharm_files():
|
2018-04-09 01:03:29 +03:00
|
|
|
idea_dir_path = ".idea"
|
2018-02-07 22:52:52 +03:00
|
|
|
if os.path.exists(idea_dir_path):
|
|
|
|
shutil.rmtree(idea_dir_path)
|
2015-09-15 04:55:41 +03:00
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
docs_dir_path = os.path.join("docs", "pycharm")
|
2018-02-07 22:52:52 +03:00
|
|
|
if os.path.exists(docs_dir_path):
|
|
|
|
shutil.rmtree(docs_dir_path)
|
2015-09-15 04:55:41 +03:00
|
|
|
|
2015-10-15 19:29:43 +03:00
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
def remove_docker_files():
|
2018-04-09 01:03:29 +03:00
|
|
|
shutil.rmtree("compose")
|
2015-09-10 03:56:27 +03:00
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
file_names = ["local.yml", "production.yml", ".dockerignore"]
|
2018-02-07 22:52:52 +03:00
|
|
|
for file_name in file_names:
|
2018-03-08 15:56:15 +03:00
|
|
|
os.remove(file_name)
|
2021-12-20 12:39:23 +03:00
|
|
|
if "{{ cookiecutter.use_pycharm }}".lower() == "y":
|
|
|
|
file_names = ["docker_compose_up_django.xml", "docker_compose_up_docs.xml"]
|
|
|
|
for file_name in file_names:
|
|
|
|
os.remove(os.path.join(".idea", "runConfigurations", file_name))
|
2015-09-10 03:56:27 +03:00
|
|
|
|
2016-06-06 00:16:02 +03:00
|
|
|
|
2018-06-28 16:43:34 +03:00
|
|
|
def remove_utility_files():
|
|
|
|
shutil.rmtree("utility")
|
|
|
|
|
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
def remove_heroku_files():
|
2018-10-16 22:22:04 +03:00
|
|
|
file_names = ["Procfile", "runtime.txt", "requirements.txt"]
|
2018-02-07 22:52:52 +03:00
|
|
|
for file_name in file_names:
|
2019-03-18 20:49:43 +03:00
|
|
|
if (
|
|
|
|
file_name == "requirements.txt"
|
2019-12-06 10:55:00 +03:00
|
|
|
and "{{ cookiecutter.ci_tool }}".lower() == "travis"
|
2019-03-18 20:49:43 +03:00
|
|
|
):
|
2018-10-16 22:22:04 +03:00
|
|
|
# don't remove the file if we are using travisci but not using heroku
|
|
|
|
continue
|
2018-03-08 15:56:15 +03:00
|
|
|
os.remove(file_name)
|
2020-05-01 20:36:01 +03:00
|
|
|
remove_heroku_build_hooks()
|
|
|
|
|
|
|
|
|
|
|
|
def remove_heroku_build_hooks():
|
|
|
|
shutil.rmtree("bin")
|
2016-03-23 20:51:25 +03:00
|
|
|
|
2016-04-08 10:45:09 +03:00
|
|
|
|
2023-01-29 15:12:12 +03:00
|
|
|
def remove_sass_files():
|
|
|
|
shutil.rmtree(os.path.join("{{cookiecutter.project_slug}}", "static", "sass"))
|
|
|
|
|
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
def remove_gulp_files():
|
2018-04-09 01:03:29 +03:00
|
|
|
file_names = ["gulpfile.js"]
|
2018-02-07 22:52:52 +03:00
|
|
|
for file_name in file_names:
|
2018-03-08 15:56:15 +03:00
|
|
|
os.remove(file_name)
|
2022-03-20 18:00:40 +03:00
|
|
|
|
|
|
|
|
2023-01-29 15:12:12 +03:00
|
|
|
def remove_webpack_files():
|
|
|
|
shutil.rmtree("webpack")
|
|
|
|
remove_vendors_js()
|
|
|
|
|
|
|
|
|
|
|
|
def remove_vendors_js():
|
|
|
|
vendors_js_path = os.path.join(
|
|
|
|
"{{ cookiecutter.project_slug }}",
|
|
|
|
"static",
|
|
|
|
"js",
|
|
|
|
"vendors.js",
|
|
|
|
)
|
|
|
|
if os.path.exists(vendors_js_path):
|
|
|
|
os.remove(vendors_js_path)
|
2016-04-08 10:45:09 +03:00
|
|
|
|
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
def remove_packagejson_file():
|
2018-04-09 01:03:29 +03:00
|
|
|
file_names = ["package.json"]
|
2018-02-07 22:52:52 +03:00
|
|
|
for file_name in file_names:
|
2018-03-08 15:56:15 +03:00
|
|
|
os.remove(file_name)
|
2016-04-08 10:45:09 +03:00
|
|
|
|
2016-06-04 03:31:36 +03:00
|
|
|
|
2023-01-29 15:12:12 +03:00
|
|
|
def update_package_json(remove_dev_deps=None, remove_keys=None, scripts=None):
|
|
|
|
remove_dev_deps = remove_dev_deps or []
|
|
|
|
remove_keys = remove_keys or []
|
|
|
|
scripts = scripts or {}
|
|
|
|
with open("package.json", mode="r") as fd:
|
|
|
|
content = json.load(fd)
|
|
|
|
for package_name in remove_dev_deps:
|
|
|
|
content["devDependencies"].pop(package_name)
|
|
|
|
for key in remove_keys:
|
|
|
|
content.pop(key)
|
|
|
|
content["scripts"].update(scripts)
|
|
|
|
with open("package.json", mode="w") as fd:
|
|
|
|
json.dump(content, fd, ensure_ascii=False, indent=2)
|
|
|
|
fd.write("\n")
|
|
|
|
|
|
|
|
|
|
|
|
def handle_js_runner(choice, use_docker, use_async):
|
|
|
|
if choice == "Gulp":
|
|
|
|
update_package_json(
|
|
|
|
remove_dev_deps=[
|
|
|
|
"@babel/core",
|
|
|
|
"@babel/preset-env",
|
|
|
|
"babel-loader",
|
|
|
|
"concurrently",
|
|
|
|
"css-loader",
|
|
|
|
"mini-css-extract-plugin",
|
|
|
|
"postcss-loader",
|
|
|
|
"postcss-preset-env",
|
|
|
|
"sass-loader",
|
|
|
|
"webpack",
|
|
|
|
"webpack-bundle-tracker",
|
|
|
|
"webpack-cli",
|
|
|
|
"webpack-dev-server",
|
|
|
|
"webpack-merge",
|
|
|
|
],
|
|
|
|
remove_keys=["babel"],
|
|
|
|
scripts={
|
|
|
|
"dev": "gulp",
|
|
|
|
"build": "gulp generate-assets",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
remove_webpack_files()
|
|
|
|
elif choice == "Webpack":
|
|
|
|
scripts = {
|
|
|
|
"dev": "webpack serve --config webpack/dev.config.js",
|
|
|
|
"build": "webpack --config webpack/prod.config.js",
|
|
|
|
}
|
|
|
|
remove_dev_deps = [
|
|
|
|
"browser-sync",
|
|
|
|
"cssnano",
|
|
|
|
"gulp",
|
|
|
|
"gulp-imagemin",
|
|
|
|
"gulp-plumber",
|
|
|
|
"gulp-postcss",
|
|
|
|
"gulp-rename",
|
|
|
|
"gulp-sass",
|
|
|
|
"gulp-uglify-es",
|
|
|
|
]
|
|
|
|
if not use_docker:
|
|
|
|
dev_django_cmd = (
|
|
|
|
"uvicorn config.asgi:application --reload"
|
|
|
|
if use_async
|
|
|
|
else "python manage.py runserver_plus"
|
|
|
|
)
|
|
|
|
scripts.update(
|
|
|
|
{
|
|
|
|
"dev": "concurrently npm:dev:*",
|
|
|
|
"dev:webpack": "webpack serve --config webpack/dev.config.js",
|
|
|
|
"dev:django": dev_django_cmd,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
remove_dev_deps.append("concurrently")
|
|
|
|
update_package_json(remove_dev_deps=remove_dev_deps, scripts=scripts)
|
|
|
|
remove_gulp_files()
|
|
|
|
|
|
|
|
|
2019-04-02 17:26:55 +03:00
|
|
|
def remove_celery_files():
|
|
|
|
file_names = [
|
|
|
|
os.path.join("config", "celery_app.py"),
|
|
|
|
os.path.join("{{ cookiecutter.project_slug }}", "users", "tasks.py"),
|
|
|
|
os.path.join(
|
|
|
|
"{{ cookiecutter.project_slug }}", "users", "tests", "test_tasks.py"
|
|
|
|
),
|
|
|
|
]
|
|
|
|
for file_name in file_names:
|
|
|
|
os.remove(file_name)
|
2018-02-07 22:52:52 +03:00
|
|
|
|
|
|
|
|
2020-03-24 22:40:14 +03:00
|
|
|
def remove_async_files():
|
|
|
|
file_names = [
|
|
|
|
os.path.join("config", "asgi.py"),
|
|
|
|
os.path.join("config", "websocket.py"),
|
|
|
|
]
|
|
|
|
for file_name in file_names:
|
|
|
|
os.remove(file_name)
|
|
|
|
|
|
|
|
|
2018-03-04 15:11:54 +03:00
|
|
|
def remove_dottravisyml_file():
|
2018-04-09 01:03:29 +03:00
|
|
|
os.remove(".travis.yml")
|
2018-03-04 15:11:54 +03:00
|
|
|
|
|
|
|
|
2019-12-06 10:55:00 +03:00
|
|
|
def remove_dotgitlabciyml_file():
|
|
|
|
os.remove(".gitlab-ci.yml")
|
|
|
|
|
|
|
|
|
2020-09-21 13:20:24 +03:00
|
|
|
def remove_dotgithub_folder():
|
|
|
|
shutil.rmtree(".github")
|
|
|
|
|
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
def generate_random_string(
|
|
|
|
length, using_digits=False, using_ascii_letters=False, using_punctuation=False
|
|
|
|
):
|
2016-06-24 17:59:55 +03:00
|
|
|
"""
|
2018-02-07 22:52:52 +03:00
|
|
|
Example:
|
|
|
|
opting out for 50 symbol-long, [a-z][A-Z][0-9] string
|
|
|
|
would yield log_2((26+26+50)^50) ~= 334 bit strength.
|
2016-06-24 17:59:55 +03:00
|
|
|
"""
|
2018-02-07 22:52:52 +03:00
|
|
|
if not using_sysrandom:
|
|
|
|
return None
|
|
|
|
|
|
|
|
symbols = []
|
|
|
|
if using_digits:
|
|
|
|
symbols += string.digits
|
|
|
|
if using_ascii_letters:
|
|
|
|
symbols += string.ascii_letters
|
|
|
|
if using_punctuation:
|
2018-09-17 19:58:45 +03:00
|
|
|
all_punctuation = set(string.punctuation)
|
|
|
|
# These symbols can cause issues in environment variables
|
|
|
|
unsuitable = {"'", '"', "\\", "$"}
|
|
|
|
suitable = all_punctuation.difference(unsuitable)
|
|
|
|
symbols += "".join(suitable)
|
2018-04-09 01:03:29 +03:00
|
|
|
return "".join([random.choice(symbols) for _ in range(length)])
|
|
|
|
|
|
|
|
|
|
|
|
def set_flag(file_path, flag, value=None, formatted=None, *args, **kwargs):
|
2018-02-07 22:52:52 +03:00
|
|
|
if value is None:
|
|
|
|
random_string = generate_random_string(*args, **kwargs)
|
|
|
|
if random_string is None:
|
2018-03-08 15:56:15 +03:00
|
|
|
print(
|
2021-11-26 18:41:50 +03:00
|
|
|
"We couldn't find a secure pseudo-random number generator on your "
|
|
|
|
"system. Please, make sure to manually {} later.".format(flag)
|
2018-02-07 22:52:52 +03:00
|
|
|
)
|
|
|
|
random_string = flag
|
2018-03-08 15:56:15 +03:00
|
|
|
if formatted is not None:
|
|
|
|
random_string = formatted.format(random_string)
|
2018-02-07 22:52:52 +03:00
|
|
|
value = random_string
|
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
with open(file_path, "r+") as f:
|
2018-02-07 22:52:52 +03:00
|
|
|
file_contents = f.read().replace(flag, value)
|
|
|
|
f.seek(0)
|
|
|
|
f.write(file_contents)
|
|
|
|
f.truncate()
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
def set_django_secret_key(file_path):
|
|
|
|
django_secret_key = set_flag(
|
|
|
|
file_path,
|
2018-04-09 01:03:29 +03:00
|
|
|
"!!!SET DJANGO_SECRET_KEY!!!",
|
2018-03-08 15:56:15 +03:00
|
|
|
length=64,
|
2018-02-07 22:52:52 +03:00
|
|
|
using_digits=True,
|
2018-04-09 01:03:29 +03:00
|
|
|
using_ascii_letters=True,
|
2018-02-07 22:52:52 +03:00
|
|
|
)
|
|
|
|
return django_secret_key
|
|
|
|
|
|
|
|
|
2018-03-08 15:56:15 +03:00
|
|
|
def set_django_admin_url(file_path):
|
|
|
|
django_admin_url = set_flag(
|
|
|
|
file_path,
|
2018-04-09 01:03:29 +03:00
|
|
|
"!!!SET DJANGO_ADMIN_URL!!!",
|
2018-05-14 10:09:24 +03:00
|
|
|
formatted="{}/",
|
2018-03-08 15:56:15 +03:00
|
|
|
length=32,
|
|
|
|
using_digits=True,
|
2018-04-09 01:03:29 +03:00
|
|
|
using_ascii_letters=True,
|
2018-03-08 15:56:15 +03:00
|
|
|
)
|
|
|
|
return django_admin_url
|
|
|
|
|
|
|
|
|
2018-06-27 19:33:21 +03:00
|
|
|
def generate_random_user():
|
|
|
|
return generate_random_string(length=32, using_ascii_letters=True)
|
|
|
|
|
|
|
|
|
2018-05-05 13:47:58 +03:00
|
|
|
def generate_postgres_user(debug=False):
|
2018-06-27 19:33:21 +03:00
|
|
|
return DEBUG_VALUE if debug else generate_random_user()
|
2018-03-08 15:56:15 +03:00
|
|
|
|
|
|
|
|
2018-05-05 13:47:58 +03:00
|
|
|
def set_postgres_user(file_path, value):
|
2019-03-18 20:49:43 +03:00
|
|
|
postgres_user = set_flag(file_path, "!!!SET POSTGRES_USER!!!", value=value)
|
2018-02-07 22:52:52 +03:00
|
|
|
return postgres_user
|
|
|
|
|
|
|
|
|
2018-05-05 13:47:58 +03:00
|
|
|
def set_postgres_password(file_path, value=None):
|
2018-02-07 22:52:52 +03:00
|
|
|
postgres_password = set_flag(
|
|
|
|
file_path,
|
2018-04-09 01:03:29 +03:00
|
|
|
"!!!SET POSTGRES_PASSWORD!!!",
|
2018-05-05 13:47:58 +03:00
|
|
|
value=value,
|
2018-03-08 15:56:15 +03:00
|
|
|
length=64,
|
2018-02-07 22:52:52 +03:00
|
|
|
using_digits=True,
|
2018-04-09 01:03:29 +03:00
|
|
|
using_ascii_letters=True,
|
2018-02-07 22:52:52 +03:00
|
|
|
)
|
|
|
|
return postgres_password
|
|
|
|
|
|
|
|
|
2018-06-27 19:33:21 +03:00
|
|
|
def set_celery_flower_user(file_path, value):
|
|
|
|
celery_flower_user = set_flag(
|
2019-03-18 20:49:43 +03:00
|
|
|
file_path, "!!!SET CELERY_FLOWER_USER!!!", value=value
|
2018-06-27 19:33:21 +03:00
|
|
|
)
|
|
|
|
return celery_flower_user
|
|
|
|
|
|
|
|
|
|
|
|
def set_celery_flower_password(file_path, value=None):
|
|
|
|
celery_flower_password = set_flag(
|
|
|
|
file_path,
|
|
|
|
"!!!SET CELERY_FLOWER_PASSWORD!!!",
|
|
|
|
value=value,
|
|
|
|
length=64,
|
|
|
|
using_digits=True,
|
|
|
|
using_ascii_letters=True,
|
|
|
|
)
|
|
|
|
return celery_flower_password
|
|
|
|
|
|
|
|
|
2021-12-16 14:07:47 +03:00
|
|
|
def append_to_gitignore_file(ignored_line):
|
2018-04-09 01:03:29 +03:00
|
|
|
with open(".gitignore", "a") as gitignore_file:
|
2021-12-16 14:07:47 +03:00
|
|
|
gitignore_file.write(ignored_line)
|
|
|
|
gitignore_file.write("\n")
|
2018-03-08 15:56:15 +03:00
|
|
|
|
|
|
|
|
2019-03-18 20:49:43 +03:00
|
|
|
def set_flags_in_envs(postgres_user, celery_flower_user, debug=False):
|
2018-06-27 19:33:21 +03:00
|
|
|
local_django_envs_path = os.path.join(".envs", ".local", ".django")
|
|
|
|
production_django_envs_path = os.path.join(".envs", ".production", ".django")
|
2018-04-09 01:03:29 +03:00
|
|
|
local_postgres_envs_path = os.path.join(".envs", ".local", ".postgres")
|
2018-06-27 19:33:21 +03:00
|
|
|
production_postgres_envs_path = os.path.join(".envs", ".production", ".postgres")
|
2018-02-07 22:52:52 +03:00
|
|
|
|
2018-03-08 15:56:15 +03:00
|
|
|
set_django_secret_key(production_django_envs_path)
|
|
|
|
set_django_admin_url(production_django_envs_path)
|
2018-02-07 22:52:52 +03:00
|
|
|
|
2018-06-27 19:33:21 +03:00
|
|
|
set_postgres_user(local_postgres_envs_path, value=postgres_user)
|
2019-03-18 20:49:43 +03:00
|
|
|
set_postgres_password(
|
|
|
|
local_postgres_envs_path, value=DEBUG_VALUE if debug else None
|
|
|
|
)
|
2018-03-08 15:56:15 +03:00
|
|
|
set_postgres_user(production_postgres_envs_path, value=postgres_user)
|
2019-03-18 20:49:43 +03:00
|
|
|
set_postgres_password(
|
|
|
|
production_postgres_envs_path, value=DEBUG_VALUE if debug else None
|
|
|
|
)
|
2018-02-07 22:52:52 +03:00
|
|
|
|
2018-06-27 19:33:21 +03:00
|
|
|
set_celery_flower_user(local_django_envs_path, value=celery_flower_user)
|
2019-03-18 20:49:43 +03:00
|
|
|
set_celery_flower_password(
|
|
|
|
local_django_envs_path, value=DEBUG_VALUE if debug else None
|
|
|
|
)
|
2018-06-27 19:33:21 +03:00
|
|
|
set_celery_flower_user(production_django_envs_path, value=celery_flower_user)
|
2019-03-18 20:49:43 +03:00
|
|
|
set_celery_flower_password(
|
|
|
|
production_django_envs_path, value=DEBUG_VALUE if debug else None
|
|
|
|
)
|
2018-06-27 19:33:21 +03:00
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
|
2018-03-08 15:56:15 +03:00
|
|
|
def set_flags_in_settings_files():
|
2018-04-09 01:03:29 +03:00
|
|
|
set_django_secret_key(os.path.join("config", "settings", "local.py"))
|
|
|
|
set_django_secret_key(os.path.join("config", "settings", "test.py"))
|
2018-02-07 22:52:52 +03:00
|
|
|
|
|
|
|
|
2018-03-08 15:56:15 +03:00
|
|
|
def remove_envs_and_associated_files():
|
2018-04-09 01:03:29 +03:00
|
|
|
shutil.rmtree(".envs")
|
|
|
|
os.remove("merge_production_dotenvs_in_dotenv.py")
|
2023-01-28 18:10:45 +03:00
|
|
|
shutil.rmtree("tests")
|
2018-02-07 22:52:52 +03:00
|
|
|
|
|
|
|
|
2018-03-27 18:40:44 +03:00
|
|
|
def remove_celery_compose_dirs():
|
2018-04-09 01:03:29 +03:00
|
|
|
shutil.rmtree(os.path.join("compose", "local", "django", "celery"))
|
|
|
|
shutil.rmtree(os.path.join("compose", "production", "django", "celery"))
|
2018-03-27 18:40:44 +03:00
|
|
|
|
|
|
|
|
2019-03-25 15:10:55 +03:00
|
|
|
def remove_node_dockerfile():
|
|
|
|
shutil.rmtree(os.path.join("compose", "local", "node"))
|
|
|
|
|
|
|
|
|
2019-10-21 10:59:37 +03:00
|
|
|
def remove_aws_dockerfile():
|
|
|
|
shutil.rmtree(os.path.join("compose", "production", "aws"))
|
|
|
|
|
|
|
|
|
2019-09-13 09:43:12 +03:00
|
|
|
def remove_drf_starter_files():
|
|
|
|
os.remove(os.path.join("config", "api_router.py"))
|
|
|
|
shutil.rmtree(os.path.join("{{cookiecutter.project_slug}}", "users", "api"))
|
2020-04-29 01:18:52 +03:00
|
|
|
os.remove(
|
|
|
|
os.path.join(
|
|
|
|
"{{cookiecutter.project_slug}}", "users", "tests", "test_drf_urls.py"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
os.remove(
|
|
|
|
os.path.join(
|
|
|
|
"{{cookiecutter.project_slug}}", "users", "tests", "test_drf_views.py"
|
|
|
|
)
|
|
|
|
)
|
2022-01-19 21:14:36 +03:00
|
|
|
os.remove(
|
|
|
|
os.path.join(
|
2022-02-16 15:25:32 +03:00
|
|
|
"{{cookiecutter.project_slug}}", "users", "tests", "test_swagger.py"
|
2022-01-19 21:14:36 +03:00
|
|
|
)
|
|
|
|
)
|
2019-09-13 09:43:12 +03:00
|
|
|
|
|
|
|
|
2020-03-03 23:28:02 +03:00
|
|
|
def remove_storages_module():
|
|
|
|
os.remove(os.path.join("{{cookiecutter.project_slug}}", "utils", "storages.py"))
|
|
|
|
|
|
|
|
|
2018-02-07 22:52:52 +03:00
|
|
|
def main():
|
2018-06-27 19:33:21 +03:00
|
|
|
debug = "{{ cookiecutter.debug }}".lower() == "y"
|
|
|
|
|
|
|
|
set_flags_in_envs(
|
|
|
|
DEBUG_VALUE if debug else generate_random_user(),
|
|
|
|
DEBUG_VALUE if debug else generate_random_user(),
|
|
|
|
debug=debug,
|
|
|
|
)
|
2018-03-08 15:56:15 +03:00
|
|
|
set_flags_in_settings_files()
|
2018-02-07 22:52:52 +03:00
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
if "{{ cookiecutter.open_source_license }}" == "Not open source":
|
2018-03-08 15:56:15 +03:00
|
|
|
remove_open_source_files()
|
2018-04-09 01:03:29 +03:00
|
|
|
if "{{ cookiecutter.open_source_license}}" != "GPLv3":
|
2018-02-07 22:52:52 +03:00
|
|
|
remove_gplv3_files()
|
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
if "{{ cookiecutter.use_pycharm }}".lower() == "n":
|
2018-02-07 22:52:52 +03:00
|
|
|
remove_pycharm_files()
|
|
|
|
|
2018-06-28 16:43:34 +03:00
|
|
|
if "{{ cookiecutter.use_docker }}".lower() == "y":
|
|
|
|
remove_utility_files()
|
|
|
|
else:
|
2018-02-07 22:52:52 +03:00
|
|
|
remove_docker_files()
|
|
|
|
|
2019-10-21 12:12:53 +03:00
|
|
|
if (
|
|
|
|
"{{ cookiecutter.use_docker }}".lower() == "y"
|
2022-03-20 18:00:40 +03:00
|
|
|
and "{{ cookiecutter.cloud_provider}}" != "AWS"
|
2019-10-21 12:12:53 +03:00
|
|
|
):
|
2019-10-21 10:59:37 +03:00
|
|
|
remove_aws_dockerfile()
|
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
if "{{ cookiecutter.use_heroku }}".lower() == "n":
|
2018-03-04 14:43:54 +03:00
|
|
|
remove_heroku_files()
|
2022-03-20 18:00:40 +03:00
|
|
|
elif "{{ cookiecutter.frontend_pipeline }}" != "Django Compressor":
|
2020-05-01 20:36:01 +03:00
|
|
|
remove_heroku_build_hooks()
|
2018-02-07 22:52:52 +03:00
|
|
|
|
2018-05-05 12:37:10 +03:00
|
|
|
if (
|
|
|
|
"{{ cookiecutter.use_docker }}".lower() == "n"
|
|
|
|
and "{{ cookiecutter.use_heroku }}".lower() == "n"
|
|
|
|
):
|
2018-04-09 01:03:29 +03:00
|
|
|
if "{{ cookiecutter.keep_local_envs_in_vcs }}".lower() == "y":
|
2018-03-08 15:56:15 +03:00
|
|
|
print(
|
2018-04-09 01:03:29 +03:00
|
|
|
INFO + ".env(s) are only utilized when Docker Compose and/or "
|
2019-03-18 20:49:43 +03:00
|
|
|
"Heroku support is enabled so keeping them does not "
|
|
|
|
"make sense given your current setup." + TERMINATOR
|
2018-03-08 15:56:15 +03:00
|
|
|
)
|
|
|
|
remove_envs_and_associated_files()
|
|
|
|
else:
|
2018-04-09 01:03:29 +03:00
|
|
|
append_to_gitignore_file(".env")
|
|
|
|
append_to_gitignore_file(".envs/*")
|
|
|
|
if "{{ cookiecutter.keep_local_envs_in_vcs }}".lower() == "y":
|
|
|
|
append_to_gitignore_file("!.envs/.local/")
|
2018-03-04 14:44:37 +03:00
|
|
|
|
2023-01-29 15:12:12 +03:00
|
|
|
if "{{ cookiecutter.frontend_pipeline }}" in ["None", "Django Compressor"]:
|
2018-02-07 22:52:52 +03:00
|
|
|
remove_gulp_files()
|
2023-01-29 15:12:12 +03:00
|
|
|
remove_webpack_files()
|
|
|
|
remove_sass_files()
|
2018-02-07 22:52:52 +03:00
|
|
|
remove_packagejson_file()
|
2019-03-25 15:10:55 +03:00
|
|
|
if "{{ cookiecutter.use_docker }}".lower() == "y":
|
|
|
|
remove_node_dockerfile()
|
2023-01-29 15:12:12 +03:00
|
|
|
else:
|
|
|
|
handle_js_runner(
|
|
|
|
"{{ cookiecutter.frontend_pipeline }}",
|
|
|
|
use_docker=("{{ cookiecutter.use_docker }}".lower() == "y"),
|
|
|
|
use_async=("{{ cookiecutter.use_async }}".lower() == "y"),
|
|
|
|
)
|
2018-02-07 22:52:52 +03:00
|
|
|
|
2023-01-29 15:12:12 +03:00
|
|
|
if "{{ cookiecutter.cloud_provider }}" == "None":
|
2019-05-19 02:23:48 +03:00
|
|
|
print(
|
|
|
|
WARNING + "You chose not to use a cloud provider, "
|
|
|
|
"media files won't be served in production." + TERMINATOR
|
|
|
|
)
|
2020-03-03 23:28:02 +03:00
|
|
|
remove_storages_module()
|
2019-05-19 02:23:48 +03:00
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
if "{{ cookiecutter.use_celery }}".lower() == "n":
|
2019-04-02 17:26:55 +03:00
|
|
|
remove_celery_files()
|
2018-04-09 01:03:29 +03:00
|
|
|
if "{{ cookiecutter.use_docker }}".lower() == "y":
|
2018-03-27 18:40:44 +03:00
|
|
|
remove_celery_compose_dirs()
|
2018-02-07 22:52:52 +03:00
|
|
|
|
2022-03-20 18:00:40 +03:00
|
|
|
if "{{ cookiecutter.ci_tool }}" != "Travis":
|
2018-03-04 15:11:54 +03:00
|
|
|
remove_dottravisyml_file()
|
|
|
|
|
2022-03-20 18:00:40 +03:00
|
|
|
if "{{ cookiecutter.ci_tool }}" != "Gitlab":
|
2019-12-06 10:55:00 +03:00
|
|
|
remove_dotgitlabciyml_file()
|
|
|
|
|
2022-03-20 18:00:40 +03:00
|
|
|
if "{{ cookiecutter.ci_tool }}" != "Github":
|
2020-09-21 13:20:24 +03:00
|
|
|
remove_dotgithub_folder()
|
|
|
|
|
2019-09-13 09:43:12 +03:00
|
|
|
if "{{ cookiecutter.use_drf }}".lower() == "n":
|
|
|
|
remove_drf_starter_files()
|
|
|
|
|
2020-03-24 22:40:14 +03:00
|
|
|
if "{{ cookiecutter.use_async }}".lower() == "n":
|
|
|
|
remove_async_files()
|
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
print(SUCCESS + "Project initialized, keep up the good work!" + TERMINATOR)
|
2018-03-08 15:56:15 +03:00
|
|
|
|
2016-04-08 10:45:09 +03:00
|
|
|
|
2018-04-09 01:03:29 +03:00
|
|
|
if __name__ == "__main__":
|
2018-02-07 22:52:52 +03:00
|
|
|
main()
|