fix: black
This commit is contained in:
parent
7646c85546
commit
58677d06c0
4 changed files with 64 additions and 43 deletions
|
|
@ -3,4 +3,4 @@ from .__version__ import __version__
|
|||
|
||||
|
||||
RougailUserData = RougailUserDataEnvironment
|
||||
__all__ = ('RougailUserDataEnvironment',)
|
||||
__all__ = ("RougailUserDataEnvironment",)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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",)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue