uspješno učitana skripta
This commit is contained in:
BIN
plovidba_projekt/__pycache__/env.cpython-38.pyc
Normal file
BIN
plovidba_projekt/__pycache__/env.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
101
plovidba_projekt/env.py
Normal file
101
plovidba_projekt/env.py
Normal file
@@ -0,0 +1,101 @@
|
||||
import os
|
||||
|
||||
__all__ = [
|
||||
'BASE_DIR', 'ABS_PATH', 'ENV_BOOL', 'ENV_NUM', 'ENV_STR', 'ENV_LIST', 'PARDIR', 'ENV_TUPLE'
|
||||
]
|
||||
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
PARDIR = os.pardir
|
||||
|
||||
APPLICATION_NAME = "rgi-dev"
|
||||
|
||||
ENV_PATH = os.path.join('/etc/secrets/', APPLICATION_NAME)
|
||||
|
||||
|
||||
def ABS_PATH(*args):
|
||||
return os.path.join(BASE_DIR, *args)
|
||||
|
||||
|
||||
def ENV_BOOL(name, default=False):
|
||||
"""
|
||||
Get a boolean value from environment variable.
|
||||
If the environment variable is not set or value is not one or "true" or
|
||||
"false", the default value is returned instead.
|
||||
"""
|
||||
|
||||
if name not in os.environ:
|
||||
return default
|
||||
if os.environ[name].lower() in ['true', 'yes', '1']:
|
||||
return True
|
||||
elif os.environ[name].lower() in ['false', 'no', '0']:
|
||||
return False
|
||||
else:
|
||||
return default
|
||||
|
||||
|
||||
def ENV_NUM(name, default=None):
|
||||
"""
|
||||
Get a integer value from environment variable.
|
||||
If the environment variable is not set, the default value is returned
|
||||
instead.
|
||||
"""
|
||||
return int(os.environ.get(name, default))
|
||||
|
||||
|
||||
def ENV_STR(name, default=None):
|
||||
"""
|
||||
Get a string value from environment variable.
|
||||
If the environment variable is not set, the default value is returned
|
||||
instead.
|
||||
"""
|
||||
|
||||
return os.environ.get(name, default)
|
||||
|
||||
|
||||
def ENV_LIST(name, separator, default=None):
|
||||
"""
|
||||
Get a list of string values from environment variable.
|
||||
If the environment variable is not set, the default value is returned
|
||||
instead.
|
||||
"""
|
||||
if default is None:
|
||||
default = []
|
||||
|
||||
if name not in os.environ:
|
||||
return default
|
||||
return os.environ[name].split(separator)
|
||||
|
||||
|
||||
def ENV_TUPLE(name, separator, default=None):
|
||||
"""
|
||||
Get a tuple of string values from environment variable.
|
||||
If the environment variable is not set, the default value is returned
|
||||
instead.
|
||||
"""
|
||||
if default is None:
|
||||
default = ()
|
||||
|
||||
if name not in os.environ:
|
||||
return default
|
||||
return tuple(os.environ[name].split(separator))
|
||||
|
||||
|
||||
def _load_env_file():
|
||||
|
||||
if os.path.exists(os.path.join(BASE_DIR, ".env")):
|
||||
envfile = os.path.join(BASE_DIR, ".env")
|
||||
else:
|
||||
envfile = os.path.join(ENV_PATH, ".env")
|
||||
|
||||
if os.path.isfile(envfile):
|
||||
for line in open(envfile):
|
||||
line = line.strip()
|
||||
if not line or line.startswith('#') or '=' not in line:
|
||||
continue
|
||||
k, v = line.split('=', 1)
|
||||
os.environ[k] = v
|
||||
|
||||
|
||||
_load_env_file()
|
||||
@@ -19,6 +19,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
import os
|
||||
from osgeo import gdal
|
||||
|
||||
from .env import BASE_DIR, ENV_BOOL, ENV_LIST, ENV_NUM, ENV_STR, PARDIR # noqa
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
@@ -46,7 +47,9 @@ INSTALLED_APPS = [
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.gis',
|
||||
'django_extensions',
|
||||
# 3rd party
|
||||
'rest_framework',
|
||||
# Custom apps:
|
||||
'plovidba_aplikacija',
|
||||
|
||||
]
|
||||
@@ -127,6 +130,15 @@ USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
PROJ_LIB = ENV_STR("PROJ_LIB", None)
|
||||
GDAL_DATA = ENV_STR("GDAL_DATA", None)
|
||||
|
||||
if PROJ_LIB:
|
||||
os.environ["PROJ_LIB"] = PROJ_LIB
|
||||
|
||||
if GDAL_DATA:
|
||||
os.environ["GDAL_DATA"] = GDAL_DATA
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
@@ -138,5 +150,3 @@ STATIC_URL = 'static/'
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
|
||||
GDAL_LIBRARY_PATH = r'C:\Users\Student1\GDAL\gdal304.dll'
|
||||
|
||||
Reference in New Issue
Block a user