2018-04-03 12:49:14 +00:00
|
|
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
|
2018-02-09 13:48:37 +00:00
|
|
|
from collections import namedtuple
|
|
|
|
from os import environ
|
|
|
|
|
2018-07-26 11:59:06 +00:00
|
|
|
from tfw.decorators.lazy_property import lazy_property
|
2018-02-09 13:48:37 +00:00
|
|
|
|
2018-06-01 12:00:44 +00:00
|
|
|
|
|
|
|
class LazyEnvironment:
|
|
|
|
def __init__(self, prefix, tuple_name):
|
|
|
|
self._prefix = prefix
|
|
|
|
self._tuple_name = tuple_name
|
|
|
|
|
2018-06-02 09:48:34 +00:00
|
|
|
@lazy_property
|
2018-06-01 12:00:44 +00:00
|
|
|
def environment(self):
|
|
|
|
return self.prefixed_envvars_to_namedtuple()
|
|
|
|
|
|
|
|
def prefixed_envvars_to_namedtuple(self):
|
2018-06-04 20:16:44 +00:00
|
|
|
envvars = {
|
|
|
|
envvar.replace(self._prefix, '', 1): environ.get(envvar)
|
|
|
|
for envvar in environ.keys()
|
|
|
|
if envvar.startswith(self._prefix)
|
|
|
|
}
|
2018-06-01 12:00:44 +00:00
|
|
|
return namedtuple(self._tuple_name, envvars)(**envvars)
|