mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-15 11:33:08 +00:00
Copy config template to config file if it does not exist
This commit is contained in:
parent
b7391231aa
commit
905c02d86f
@ -3,15 +3,20 @@
|
|||||||
# Ref: https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-DATABASES
|
# Ref: https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-DATABASES
|
||||||
# Specify database parameters below as they appear in the Django docs
|
# Specify database parameters below as they appear in the Django docs
|
||||||
database:
|
database:
|
||||||
|
# Example configuration - sqlite (default)
|
||||||
ENGINE: django.db.backends.sqlite3
|
ENGINE: django.db.backends.sqlite3
|
||||||
NAME: inventree_db.sqlite3
|
NAME: inventree_db.sqlite3
|
||||||
|
|
||||||
# For more complex database installations, further parameters are required
|
# For more complex database installations, further parameters are required
|
||||||
# Refer to the django documentation for full list of options
|
# Refer to the django documentation for full list of options
|
||||||
# USER: db_username
|
|
||||||
# PASSWORD: db_password
|
# Example Configuration - MySQL
|
||||||
# HOST: db_hostname
|
#ENGINE: django.db.backends.mysql
|
||||||
# PORT: db_port
|
#NAME: inventree
|
||||||
|
#USER: inventree
|
||||||
|
#PASSWORD: password
|
||||||
|
#HOST: ''
|
||||||
|
#PORT: ''
|
||||||
|
|
||||||
# Set debug to False to run in production mode
|
# Set debug to False to run in production mode
|
||||||
debug: True
|
debug: True
|
||||||
@ -47,4 +52,4 @@ log_queries: False
|
|||||||
|
|
||||||
# Backup options
|
# Backup options
|
||||||
# Set the backup_dir parameter to store backup files in a specific location
|
# Set the backup_dir parameter to store backup files in a specific location
|
||||||
backup_dir: '/home/me/inventree-backup/'
|
backup_dir: '/mnt/c/Users/Oliver/inventree-backup/'
|
@ -1,56 +0,0 @@
|
|||||||
"""
|
|
||||||
Generates a Django SECRET_KEY file to be used by manage.py
|
|
||||||
"""
|
|
||||||
|
|
||||||
import random
|
|
||||||
import string
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
KEY_FN = 'secret_key.txt'
|
|
||||||
KEY_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
|
|
||||||
|
|
||||||
def generate_key(length=50):
|
|
||||||
""" Generate a random string
|
|
||||||
|
|
||||||
Args:
|
|
||||||
length: Number of characters in returned string (default = 50)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Randomized secret key string
|
|
||||||
"""
|
|
||||||
|
|
||||||
options = string.digits + string.ascii_letters + string.punctuation
|
|
||||||
key = ''.join([random.choice(options) for i in range(length)])
|
|
||||||
return key
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Generate Django SECRET_KEY file')
|
|
||||||
parser.add_argument('--output', help='Specify key file path', default=None)
|
|
||||||
parser.add_argument('--force', '-f', help='Override key file (if it exists)', action='store_true')
|
|
||||||
parser.add_argument('--dummy', '-d', help='Dummy run (display key only', action='store_true')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
if args.output:
|
|
||||||
key_filename = args.output
|
|
||||||
else:
|
|
||||||
key_filename = os.path.join(KEY_DIR, KEY_FN)
|
|
||||||
|
|
||||||
key_data = generate_key()
|
|
||||||
|
|
||||||
if args.dummy:
|
|
||||||
print('SECRET_KEY: {k}'.format(k=key_data))
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
if not args.force and os.path.exists(key_filename):
|
|
||||||
print("Key file already exists - '{f}'".format(f=key_filename))
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
with open(key_filename, 'w') as key_file:
|
|
||||||
print("Generating SECRET_KEY file - '{f}'".format(f=key_filename))
|
|
||||||
key_file.write(key_data)
|
|
68
InvenTree/setup.py
Normal file
68
InvenTree/setup.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
"""
|
||||||
|
Performs initial setup functions.
|
||||||
|
|
||||||
|
- Generates a Django SECRET_KEY file to be used by manage.py
|
||||||
|
- Copies config template file (if a config file does not already exist)
|
||||||
|
"""
|
||||||
|
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from shutil import copyfile
|
||||||
|
|
||||||
|
OUTPUT_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
KEY_FN = 'secret_key.txt'
|
||||||
|
CONFIG_FN = 'config.yaml'
|
||||||
|
CONFIG_TEMPLATE_FN = 'config_template.yaml'
|
||||||
|
|
||||||
|
|
||||||
|
def generate_key(length=50):
|
||||||
|
""" Generate a random string
|
||||||
|
|
||||||
|
Args:
|
||||||
|
length: Number of characters in returned string (default = 50)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Randomized secret key string
|
||||||
|
"""
|
||||||
|
|
||||||
|
options = string.digits + string.ascii_letters + string.punctuation
|
||||||
|
key = ''.join([random.choice(options) for i in range(length)])
|
||||||
|
return key
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Generate Django SECRET_KEY file')
|
||||||
|
parser.add_argument('--force', '-f', help='Override existing files', action='store_true')
|
||||||
|
parser.add_argument('--dummy', '-d', help='Dummy run (do not create any files)', action='store_true')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Places to store files
|
||||||
|
key_filename = os.path.join(OUTPUT_DIR, KEY_FN)
|
||||||
|
conf_template = os.path.join(OUTPUT_DIR, CONFIG_TEMPLATE_FN)
|
||||||
|
conf_filename = os.path.join(OUTPUT_DIR, CONFIG_FN)
|
||||||
|
|
||||||
|
# Generate secret key data
|
||||||
|
key_data = generate_key()
|
||||||
|
|
||||||
|
if args.dummy:
|
||||||
|
print('SECRET_KEY: {k}'.format(k=key_data))
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if not args.force and os.path.exists(key_filename):
|
||||||
|
print("Key file already exists - '{f}'".format(f=key_filename))
|
||||||
|
else:
|
||||||
|
with open(key_filename, 'w') as key_file:
|
||||||
|
print("Generating SECRET_KEY file - '{f}'".format(f=key_filename))
|
||||||
|
key_file.write(key_data)
|
||||||
|
|
||||||
|
if not args.force and os.path.exists(conf_filename):
|
||||||
|
print("Config file already exists (skipping)")
|
||||||
|
else:
|
||||||
|
print("Copying config template to 'config.yaml'")
|
||||||
|
copyfile(conf_template, conf_filename)
|
8
Makefile
8
Makefile
@ -19,13 +19,13 @@ migrate:
|
|||||||
requirements:
|
requirements:
|
||||||
pip3 install -U -r requirements.txt
|
pip3 install -U -r requirements.txt
|
||||||
|
|
||||||
secret:
|
setup:
|
||||||
python3 InvenTree/keygen.py
|
python3 InvenTree/setup.py
|
||||||
|
|
||||||
superuser:
|
superuser:
|
||||||
python3 InvenTree/manage.py createsuperuser
|
python3 InvenTree/manage.py createsuperuser
|
||||||
|
|
||||||
install: requirements secret migrate superuser
|
install: requirements setup migrate superuser
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
apt-get install mysql-server
|
apt-get install mysql-server
|
||||||
@ -52,4 +52,4 @@ backup:
|
|||||||
python3 InvenTree/manage.py dbbackup
|
python3 InvenTree/manage.py dbbackup
|
||||||
python3 InvenTree/manage.py mediabackup
|
python3 InvenTree/manage.py mediabackup
|
||||||
|
|
||||||
.PHONY: clean migrate requirements secret superuser install mysql style test coverage documentation backup
|
.PHONY: clean migrate requirements setup superuser install mysql style test coverage documentation backup
|
@ -15,7 +15,7 @@ To support install specific settings, a simple configuration file ``config.yaml`
|
|||||||
|
|
||||||
The default configuration file launches a *DEBUG* configuration with a simple SQLITE database backend. This default configuration file is shown below:
|
The default configuration file launches a *DEBUG* configuration with a simple SQLITE database backend. This default configuration file is shown below:
|
||||||
|
|
||||||
.. literalinclude :: ../InvenTree/config.yaml
|
.. literalinclude :: ../InvenTree/config_template.yaml
|
||||||
:language: yaml
|
:language: yaml
|
||||||
:linenos:
|
:linenos:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user