mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-29 04:54:02 +03:00
major project cleanup
This commit is contained in:
parent
0954ec8dad
commit
327d0c2038
|
@ -18,5 +18,9 @@
|
|||
"use_pycharm": "n",
|
||||
"windows": "n",
|
||||
"use_python2": "n",
|
||||
"use_docker": "y",
|
||||
"use_heroku": "n",
|
||||
"use_grunt": "n",
|
||||
"use_angular": "n",
|
||||
"open_source_license": ["MIT", "BSD", "Not open source"]
|
||||
}
|
||||
|
|
|
@ -12,13 +12,11 @@ A portion of this code was adopted from Django's standard crypto functions and
|
|||
utilities, specifically:
|
||||
https://github.com/django/django/blob/master/django/utils/crypto.py
|
||||
"""
|
||||
import hashlib
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
|
||||
from cookiecutter.config import DEFAULT_CONFIG
|
||||
|
||||
# Get the root project directory
|
||||
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
|
||||
|
||||
|
@ -27,11 +25,9 @@ try:
|
|||
random = random.SystemRandom()
|
||||
using_sysrandom = True
|
||||
except NotImplementedError:
|
||||
# import warnings
|
||||
# warnings.warn('A secure pseudo-random number generator is not available '
|
||||
# 'on your system. Falling back to Mersenne Twister.')
|
||||
using_sysrandom = False
|
||||
|
||||
|
||||
def get_random_string(
|
||||
length=50,
|
||||
allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789!@#%^&*(-_=+)'):
|
||||
|
@ -40,21 +36,15 @@ def get_random_string(
|
|||
The default length of 12 with the a-z, A-Z, 0-9 character set returns
|
||||
a 71-bit value. log_2((26+26+10)^12) =~ 71 bits
|
||||
"""
|
||||
if not using_sysrandom:
|
||||
# This is ugly, and a hack, but it makes things better than
|
||||
# the alternative of predictability. This re-seeds the PRNG
|
||||
# using a value that is hard for an attacker to predict, every
|
||||
# time a random string is required. This may change the
|
||||
# properties of the chosen random sequence slightly, but this
|
||||
# is better than absolute predictability.
|
||||
random.seed(
|
||||
hashlib.sha256(
|
||||
("%s%s%s" % (
|
||||
random.getstate(),
|
||||
time.time(),
|
||||
settings.SECRET_KEY)).encode('utf-8')
|
||||
).digest())
|
||||
return ''.join(random.choice(allowed_chars) for i in range(length))
|
||||
if using_sysrandom:
|
||||
return ''.join(random.choice(allowed_chars) for i in range(length))
|
||||
print(
|
||||
"cookiecutter-django couldn't find a secure pseudo-random number generator on your system."
|
||||
" Please change change your SECRET_KEY variables in conf/settings/local.py and env.example"
|
||||
" manually."
|
||||
)
|
||||
return "CHANGEME!!"
|
||||
|
||||
|
||||
def set_secret_key(setting_file_location):
|
||||
# Open locals.py
|
||||
|
@ -113,6 +103,40 @@ def remove_pycharm_dir(project_directory):
|
|||
docs_dir_location = os.path.join(PROJECT_DIRECTORY, 'docs/pycharm/')
|
||||
shutil.rmtree(docs_dir_location)
|
||||
|
||||
|
||||
def remove_heroku_files():
|
||||
"""
|
||||
Removes files needed for heroku if it isn't going to be used
|
||||
"""
|
||||
for filename in ["app.json", "Procfile", "requirements.txt", "runtime.txt"]:
|
||||
os.remove(os.path.join(
|
||||
PROJECT_DIRECTORY, filename
|
||||
))
|
||||
|
||||
|
||||
def remove_docker_files():
|
||||
"""
|
||||
Removes files needed for docker if it isn't going to be used
|
||||
"""
|
||||
for filename in ["dev.yml", "docker-compose.yml", ".dockerignore"]:
|
||||
os.remove(os.path.join(
|
||||
PROJECT_DIRECTORY, filename
|
||||
))
|
||||
|
||||
shutil.rmtree(os.path.join(
|
||||
PROJECT_DIRECTORY, "compose"
|
||||
))
|
||||
|
||||
|
||||
def remove_grunt_files():
|
||||
"""
|
||||
Removes files needed for grunt if it isn't going to be used
|
||||
"""
|
||||
for filename in ["Gruntfile.js", "package.json"]:
|
||||
os.remove(os.path.join(
|
||||
PROJECT_DIRECTORY, filename
|
||||
))
|
||||
|
||||
# IN PROGRESS
|
||||
# def copy_doc_files(project_directory):
|
||||
# cookiecutters_dir = DEFAULT_CONFIG['cookiecutters_dir']
|
||||
|
@ -142,5 +166,36 @@ if '{{ cookiecutter.use_celery }}'.lower() == 'n':
|
|||
if '{{ cookiecutter.use_pycharm }}'.lower() != 'y':
|
||||
remove_pycharm_dir(PROJECT_DIRECTORY)
|
||||
|
||||
# 4. Removes all heroku files if it isn't going to be used
|
||||
if '{{ cookiecutter.use_heroku }}'.lower() != 'y':
|
||||
remove_heroku_files()
|
||||
|
||||
# 5. Removes all docker files if it isn't going to be used
|
||||
if '{{ cookiecutter.use_docker }}'.lower() != 'y':
|
||||
remove_docker_files()
|
||||
|
||||
# 6. Removes all grunt files if it isn't going to be used
|
||||
if '{{ cookiecutter.use_grunt }}'.lower() != 'y':
|
||||
remove_grunt_files()
|
||||
|
||||
|
||||
# 7. Display a warning if use_docker and use_grunt are selected. Grunt isn't supported by our
|
||||
# docker config atm.
|
||||
if '{{ cookiecutter.use_grunt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y':
|
||||
print(
|
||||
"You selected to use docker and grunt. This is NOT supported out of the box for now. You "
|
||||
"can continue to use the project like you normally would, but you will need to add a "
|
||||
" grunt service to your docker configuration manually."
|
||||
)
|
||||
|
||||
# 7. Display a warning if use_docker and use_mailhog are selected. Mailhog isn't supported by our
|
||||
# docker config atm.
|
||||
if '{{ cookiecutter.use_mailhog }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y':
|
||||
print(
|
||||
"You selected to use docker and mailhog. This is NOT supported out of the box for now. You"
|
||||
" can continue to use the project like you normally would, but you will need to add a "
|
||||
" mailhog service to your docker configuration manually."
|
||||
)
|
||||
|
||||
# 4. Copy files from /docs/ to {{ cookiecutter.repo_name }}/docs/
|
||||
# copy_doc_files(PROJECT_DIRECTORY)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% raw %}{% load staticfiles i18n %}<!DOCTYPE html>
|
||||
<html lang="en" ng-app>
|
||||
<html lang="en" {% endraw %}{% if cookiecutter.use_angular == "y" %}ng-app{% endif %}{% raw %}>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
@ -23,9 +23,9 @@
|
|||
<link href="{% static 'css/project.css' %}" rel="stylesheet">
|
||||
{% endblock %}
|
||||
|
||||
{% block angular %}
|
||||
{% endraw %}{% if cookiecutter.use_angular == "y" %}{% raw %}{% block angular %}
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
|
||||
{% endblock %}
|
||||
{% endblock %}{% endraw %}{% endif %}{% raw %}
|
||||
|
||||
</head>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user