2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-12 10:05:39 +00:00

Updates to settings.py

- Create secret_key.txt if it does not exist
- Copy default settings file if it does not exist
This commit is contained in:
Oliver Walters
2021-04-02 00:06:17 +11:00
parent be41be3981
commit 8d3b9e2ca4
2 changed files with 35 additions and 28 deletions

View File

@ -3,11 +3,10 @@
from invoke import task
from shutil import copyfile
import random
import string
import os
import sys
def apps():
"""
Returns a list of installed apps
@ -27,6 +26,7 @@ def apps():
'users',
]
def localDir():
"""
Returns the directory of *THIS* file.
@ -35,6 +35,7 @@ def localDir():
"""
return os.path.dirname(os.path.abspath(__file__))
def managePyDir():
"""
Returns the directory of the manage.py file
@ -42,6 +43,7 @@ def managePyDir():
return os.path.join(localDir(), 'InvenTree')
def managePyPath():
"""
Return the path of the manage.py file
@ -49,6 +51,7 @@ def managePyPath():
return os.path.join(managePyDir(), 'manage.py')
def manage(c, cmd, pty=False):
"""
Runs a given command against django's "manage.py" script.
@ -63,32 +66,11 @@ def manage(c, cmd, pty=False):
cmd=cmd
), pty=pty)
@task(help={'length': 'Length of secret key (default=50)'})
def key(c, length=50, force=False):
"""
Generates a SECRET_KEY file which InvenTree uses for generating security hashes
"""
SECRET_KEY_FILE = os.path.join(localDir(), 'InvenTree', 'secret_key.txt')
# If a SECRET_KEY file does not exist, generate a new one!
if force or not os.path.exists(SECRET_KEY_FILE):
print("Generating SECRET_KEY file - " + SECRET_KEY_FILE)
with open(SECRET_KEY_FILE, 'w') as key_file:
options = string.digits + string.ascii_letters + string.punctuation
key = ''.join([random.choice(options) for i in range(length)])
key_file.write(key)
else:
print("SECRET_KEY file already exists - skipping")
@task(post=[key])
@task
def install(c):
"""
Installs required python packages, and runs initial setup functions.
Installs required python packages
"""
# Install required Python packages with PIP