mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-24 09:21:31 +00:00
26 lines
760 B
Python
26 lines
760 B
Python
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
from collections import namedtuple
|
|
from os import environ
|
|
|
|
from tfw.decorators.lazy_property import lazy_property
|
|
|
|
|
|
class LazyEnvironment:
|
|
def __init__(self, prefix, tuple_name):
|
|
self._prefix = prefix
|
|
self._tuple_name = tuple_name
|
|
|
|
@lazy_property
|
|
def environment(self):
|
|
return self.prefixed_envvars_to_namedtuple()
|
|
|
|
def prefixed_envvars_to_namedtuple(self):
|
|
envvars = {
|
|
envvar.replace(self._prefix, '', 1): environ.get(envvar)
|
|
for envvar in environ.keys()
|
|
if envvar.startswith(self._prefix)
|
|
}
|
|
return namedtuple(self._tuple_name, envvars)(**envvars)
|