diff --git a/src/rougail/user_data_environment/__init__.py b/src/rougail/user_data_environment/__init__.py index f8cb9f4..a3b709e 100644 --- a/src/rougail/user_data_environment/__init__.py +++ b/src/rougail/user_data_environment/__init__.py @@ -3,4 +3,4 @@ from .__version__ import __version__ RougailUserData = RougailUserDataEnvironment -__all__ = ('RougailUserDataEnvironment',) +__all__ = ("RougailUserDataEnvironment",) diff --git a/src/rougail/user_data_environment/annotator.py b/src/rougail/user_data_environment/annotator.py index 306be33..8d56bf5 100644 --- a/src/rougail/user_data_environment/annotator.py +++ b/src/rougail/user_data_environment/annotator.py @@ -18,6 +18,7 @@ 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 """ + from rougail.error import DictConsistencyError from rougail.annotator.variable import Walk from .i18n import _ @@ -25,9 +26,9 @@ from .i18n import _ class Annotator(Walk): """Annotate for environment""" - + level = 95 - + def __init__( self, objectspace, @@ -42,11 +43,19 @@ class Annotator(Walk): def check_family(self): for family in self.get_families(): if family.name != family.name.lower(): - msg = _('family name must be a lowercase name when we want to use user data "environment", so "{0}" is invalid') - raise DictConsistencyError(msg.format(family.name), 200, family.xmlfiles) + msg = _( + 'family name must be a lowercase name when we want to use user data "environment", so "{0}" is invalid' + ) + raise DictConsistencyError( + msg.format(family.name), 200, family.xmlfiles + ) def check_variable(self): for variable in self.get_variables(): if variable.name != variable.name.lower(): - msg = _('variable name must be a lowercase name when we want to use user data "environment", so "{0}" is invalid') - raise DictConsistencyError(msg.format(variable.name), 201, variable.xmlfiles) + msg = _( + 'variable name must be a lowercase name when we want to use user data "environment", so "{0}" is invalid' + ) + raise DictConsistencyError( + msg.format(variable.name), 201, variable.xmlfiles + ) diff --git a/src/rougail/user_data_environment/config.py b/src/rougail/user_data_environment/config.py index 6143a7a..7f01d52 100644 --- a/src/rougail/user_data_environment/config.py +++ b/src/rougail/user_data_environment/config.py @@ -22,9 +22,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -def get_rougail_config(*, - backward_compatibility=True, - ) -> dict: +def get_rougail_config( + *, + backward_compatibility=True, +) -> dict: options = """ environment: description: Define values from the environment @@ -40,11 +41,12 @@ environment: variable: main_namespace when_not: null """ - return {'name': 'environment', - 'process': 'user data', - 'options': options, - 'level': 50, - } + return { + "name": "environment", + "process": "user data", + "options": options, + "level": 50, + } -__all__ = ('get_rougail_config',) +__all__ = ("get_rougail_config",) diff --git a/src/rougail/user_data_environment/data.py b/src/rougail/user_data_environment/data.py index 2f0c36f..09a469e 100644 --- a/src/rougail/user_data_environment/data.py +++ b/src/rougail/user_data_environment/data.py @@ -18,6 +18,7 @@ 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 rougail.object_model import CONVERT_OPTION from rougail.config import RougailConfig @@ -26,36 +27,41 @@ from tiramisu.error import ValueOptionError class RougailUserDataEnvironment: - def __init__(self, - config: 'Config', - *, - rougailconfig: RougailConfig=None, - ): + def __init__( + self, + config: "Config", + *, + rougailconfig: RougailConfig = None, + ): # this is the tiramisu config object self.config = config if rougailconfig is None: rougailconfig = RougailConfig - user_data = rougailconfig['step.user_data'] - if 'environment' not in user_data: - user_data.append('environment') - rougailconfig['step.user_data'] = user_data - user_data = rougailconfig['step.user_data'] + user_data = rougailconfig["step.user_data"] + if "environment" not in user_data: + user_data.append("environment") + rougailconfig["step.user_data"] = user_data + user_data = rougailconfig["step.user_data"] self.rougailconfig = rougailconfig - if 'environment' not in user_data: - raise ExtentionError('environment is not set in step.user_data') + if "environment" not in user_data: + raise ExtentionError("environment is not set in step.user_data") self.errors = [] self.warnings = [] def run(self): values = self.parse() - return [{'source': 'environment variable', - 'errors': self.errors, - 'warnings': self.warnings, - 'values': values, - 'options': {'multi_separator': ',', - 'needs_convert': True, - }, - }] + return [ + { + "source": "environment variable", + "errors": self.errors, + "warnings": self.warnings, + "values": values, + "options": { + "multi_separator": ",", + "needs_convert": True, + }, + } + ] def parse(self): variables = {} @@ -65,23 +71,27 @@ class RougailUserDataEnvironment: variables.update(get_rougail_environment(option.name())) else: return variables - return get_rougail_environment(None, self.rougailconfig['environment.default_environment_name']) + return get_rougail_environment( + None, self.rougailconfig["environment.default_environment_name"] + ) def get_rougail_environment(namespace, environment_name=None): """gets all the rougail environment variables and their values - :sample: {'VARINT': '5', 'VARNAME34': '58, 22', 'VARNAME2': 'tata', + :sample: {'VARINT': '5', 'VARNAME34': '58, 22', 'VARNAME2': 'tata', 'VARNAME1': 'titi', 'MYFAMILY.VARNAME3': 'spam'} :returns: rougail environment variables as a key/value dict """ # then we filter the ROUGAIL_ environment variables if namespace is None: - rougail_environment_var = environment_name.upper() + '_' + rougail_environment_var = environment_name.upper() + "_" len_env = len(rougail_environment_var) else: - rougail_environment_var = namespace.upper() + '.' + rougail_environment_var = namespace.upper() + "." len_env = 0 - return {envvar[len_env:].lower(): envval - for envvar, envval in os.environ.items() - if envvar.startswith(rougail_environment_var)} + return { + envvar[len_env:].lower(): envval + for envvar, envval in os.environ.items() + if envvar.startswith(rougail_environment_var) + }