environment variables warnings
This commit is contained in:
parent
13be703d81
commit
146ab88eab
2 changed files with 15 additions and 32 deletions
|
@ -20,7 +20,6 @@ along with this program; if not, write to the Free Software
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
from .helper import get_rougail_environment
|
||||
from .helper import get_rougail_environment_var, get_rougail_environment_dict
|
||||
|
||||
from rougail.object_model import CONVERT_OPTION
|
||||
from rougail.config import RougailConfig
|
||||
|
@ -51,20 +50,17 @@ class RougailUserDataEnvironment:
|
|||
else:
|
||||
self.errors = []
|
||||
self.warnings = []
|
||||
# FIXME a enlever
|
||||
# this variable will be used for generating warnings
|
||||
# about unused ROUGAIL_ environment variables
|
||||
self.unused_environment_var = get_rougail_environment_var()
|
||||
|
||||
def run(self):
|
||||
self.config.property.read_write()
|
||||
self.parse(self.config)
|
||||
self.config.property.read_only()
|
||||
# FIXME à refaire avec le dico directement
|
||||
# if there are unused environment variables
|
||||
if len(self.unused_environment_var):
|
||||
unused_environment_var_str = " ".join(self.unused_environment_var)
|
||||
self.warnings.append("the rougail environment variables were not used : " + unused_environment_var_str)
|
||||
# about unused ROUGAIL_ environment variables
|
||||
# FIXME
|
||||
# if len(self.rougail_environment_vars):
|
||||
# unused_env_var_str = " ".join(self.rougail_environment_vars.keys())
|
||||
# self.warnings.append("the following rougail environment variables "
|
||||
# "are not used : " + unused_env_var_str)
|
||||
|
||||
def parse(self, config):
|
||||
for option in config:
|
||||
|
@ -82,9 +78,9 @@ class RougailUserDataEnvironment:
|
|||
option_name = option.path()
|
||||
# the bash variable are in upper case
|
||||
option_name = option_name.upper()
|
||||
# FIXME : A REFAIRE
|
||||
# this is used only for warning purposes
|
||||
if option_name not in self.unused_environment_var:
|
||||
rougail_environment_vars = get_rougail_environment()
|
||||
# if the option is not in the bash environment, do nothing
|
||||
if option_name not in rougail_environment_vars.keys():
|
||||
return
|
||||
# actually the rougail type **is not** the same thing as
|
||||
# the tiramisu type, which is in `option.type`
|
||||
|
@ -94,11 +90,7 @@ class RougailUserDataEnvironment:
|
|||
# carefull, the coercion function 'func' could be None
|
||||
# -> in this case, do nothing
|
||||
type_obj = CONVERT_OPTION.get(option_type, {}).get("func")
|
||||
self.unused_environment_var.remove(option_name)
|
||||
# let's parse the environment variables values
|
||||
# FIXME enlever les deux fonction de helper
|
||||
# FIXME et faire un pop (un del plutot) option_bash_value = self.unused_environment_var.pop(option_name)
|
||||
option_bash_value = get_rougail_environment_dict()[option_name]
|
||||
option_bash_value = rougail_environment_vars.pop(option_name)
|
||||
if ismulti:
|
||||
# here we expect the bash option value of a multi to be coma separated:
|
||||
option_bash_value = [opt.strip() for opt in option_bash_value.split(",")]
|
||||
|
@ -107,3 +99,4 @@ class RougailUserDataEnvironment:
|
|||
elif type_obj:
|
||||
option_bash_value = type_obj(option_bash_value)
|
||||
option.value.set(option_bash_value)
|
||||
print(rougail_environment_vars)
|
||||
|
|
|
@ -20,28 +20,17 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from .config import rougail_environment_var
|
||||
|
||||
def get_rougail_environment_var():
|
||||
"lists all rougail environment variables (that is, wich startswith ROUGAIL_)"
|
||||
all_envvar = os.environ
|
||||
return [envvar.replace(rougail_environment_var, '') for envvar in all_envvar if envvar.startswith(rougail_environment_var)]
|
||||
|
||||
def get_rougail_environment_dict():
|
||||
"rougail environment variables as a key/value dict"
|
||||
rougail_environment_dict = dict()
|
||||
for var in get_rougail_environment_var():
|
||||
rougail_environment_dict[var] = os.environ[rougail_environment_var + var]
|
||||
return rougail_environment_dict
|
||||
|
||||
def get_rougail_environment():
|
||||
"""gets all the rougail environment variables and their values
|
||||
|
||||
|
||||
:sample: {'VARINT': '5', 'VARNAME34': '58, 22', 'VARNAME2': 'tata',
|
||||
'VARNAME1': 'titi', 'MYFAMILY.VARNAME3': 'spam'}
|
||||
:returns: rougail environment variables as a key/value dict
|
||||
{MYVARIABLE: my_value}
|
||||
"""
|
||||
# first we look at all environment variables
|
||||
all_envvar = os.environ
|
||||
|
@ -49,6 +38,7 @@ def get_rougail_environment():
|
|||
rougail_envvar = [envvar.replace(rougail_environment_var, '')
|
||||
for envvar in all_envvar
|
||||
if envvar.startswith(rougail_environment_var)]
|
||||
rougail_environment_dict = dict()
|
||||
for var in rougail_envvar:
|
||||
rougail_environment_dict[var] = os.environ[rougail_environment_var + var]
|
||||
return rougail_environment_dict
|
||||
|
|
Loading…
Reference in a new issue