2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-15 19:43:09 +00:00

Print warnings to stderr not stdout

This commit is contained in:
Oliver Walters 2019-08-14 12:13:31 +10:00
parent 7b4c8cdc4f
commit ea669e7562

View File

@ -11,11 +11,16 @@ database setup in this file.
""" """
import sys
import os import os
import logging import logging
import tempfile import tempfile
import yaml import yaml
def eprint(*args, **kwargs):
""" Print a warning message to stderr """
print(*args, file=sys.stderr, **kwargs)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -23,7 +28,7 @@ cfg_filename = os.path.join(BASE_DIR, 'config.yaml')
if not os.path.exists(cfg_filename): if not os.path.exists(cfg_filename):
CONFIG = {} CONFIG = {}
print("Warning: config.yaml not found - using default settings") eprint("Warning: config.yaml not found - using default settings")
else: else:
with open(cfg_filename, 'r') as cfg: with open(cfg_filename, 'r') as cfg:
CONFIG = yaml.safe_load(cfg) CONFIG = yaml.safe_load(cfg)
@ -52,7 +57,7 @@ if cors_opt:
CORS_ORIGIN_ALLOW_ALL = cors_opt.get('allow_all', False) CORS_ORIGIN_ALLOW_ALL = cors_opt.get('allow_all', False)
if CORS_ORIGIN_ALLOW_ALL: if CORS_ORIGIN_ALLOW_ALL:
print("Warning: CORS requests are allowed for any domain!") eprint("Warning: CORS requests are allowed for any domain!")
else: else:
CORS_ORIGIN_WHITELIST = cors_opt.get('whitelist', []) CORS_ORIGIN_WHITELIST = cors_opt.get('whitelist', [])
@ -156,7 +161,7 @@ DATABASES = {}
if 'database' in CONFIG: if 'database' in CONFIG:
DATABASES['default'] = CONFIG['database'] DATABASES['default'] = CONFIG['database']
else: else:
print("Warning: Database backend not specified - using default (sqlite)") eprint("Warning: Database backend not specified - using default (sqlite)")
DATABASES['default'] = { DATABASES['default'] = {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'inventree_db.sqlite3'), 'NAME': os.path.join(BASE_DIR, 'inventree_db.sqlite3'),