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
|
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
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from rougail.error import DictConsistencyError
|
from rougail.error import DictConsistencyError
|
||||||
from rougail.annotator.variable import Walk
|
from rougail.annotator.variable import Walk
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
@ -42,11 +43,19 @@ class Annotator(Walk):
|
||||||
def check_family(self):
|
def check_family(self):
|
||||||
for family in self.get_families():
|
for family in self.get_families():
|
||||||
if family.name != family.name.lower():
|
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')
|
msg = _(
|
||||||
raise DictConsistencyError(msg.format(family.name), 200, family.xmlfiles)
|
'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):
|
def check_variable(self):
|
||||||
for variable in self.get_variables():
|
for variable in self.get_variables():
|
||||||
if variable.name != variable.name.lower():
|
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')
|
msg = _(
|
||||||
raise DictConsistencyError(msg.format(variable.name), 201, variable.xmlfiles)
|
'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,7 +22,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def get_rougail_config(*,
|
def get_rougail_config(
|
||||||
|
*,
|
||||||
backward_compatibility=True,
|
backward_compatibility=True,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
options = """
|
options = """
|
||||||
|
|
@ -40,11 +41,12 @@ environment:
|
||||||
variable: main_namespace
|
variable: main_namespace
|
||||||
when_not: null
|
when_not: null
|
||||||
"""
|
"""
|
||||||
return {'name': 'environment',
|
return {
|
||||||
'process': 'user data',
|
"name": "environment",
|
||||||
'options': options,
|
"process": "user data",
|
||||||
'level': 50,
|
"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
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from rougail.object_model import CONVERT_OPTION
|
from rougail.object_model import CONVERT_OPTION
|
||||||
from rougail.config import RougailConfig
|
from rougail.config import RougailConfig
|
||||||
|
|
@ -26,8 +27,9 @@ from tiramisu.error import ValueOptionError
|
||||||
|
|
||||||
|
|
||||||
class RougailUserDataEnvironment:
|
class RougailUserDataEnvironment:
|
||||||
def __init__(self,
|
def __init__(
|
||||||
config: 'Config',
|
self,
|
||||||
|
config: "Config",
|
||||||
*,
|
*,
|
||||||
rougailconfig: RougailConfig = None,
|
rougailconfig: RougailConfig = None,
|
||||||
):
|
):
|
||||||
|
|
@ -35,27 +37,31 @@ class RougailUserDataEnvironment:
|
||||||
self.config = config
|
self.config = config
|
||||||
if rougailconfig is None:
|
if rougailconfig is None:
|
||||||
rougailconfig = RougailConfig
|
rougailconfig = RougailConfig
|
||||||
user_data = rougailconfig['step.user_data']
|
user_data = rougailconfig["step.user_data"]
|
||||||
if 'environment' not in user_data:
|
if "environment" not in user_data:
|
||||||
user_data.append('environment')
|
user_data.append("environment")
|
||||||
rougailconfig['step.user_data'] = user_data
|
rougailconfig["step.user_data"] = user_data
|
||||||
user_data = rougailconfig['step.user_data']
|
user_data = rougailconfig["step.user_data"]
|
||||||
self.rougailconfig = rougailconfig
|
self.rougailconfig = rougailconfig
|
||||||
if 'environment' not in user_data:
|
if "environment" not in user_data:
|
||||||
raise ExtentionError('environment is not set in step.user_data')
|
raise ExtentionError("environment is not set in step.user_data")
|
||||||
self.errors = []
|
self.errors = []
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
values = self.parse()
|
values = self.parse()
|
||||||
return [{'source': 'environment variable',
|
return [
|
||||||
'errors': self.errors,
|
{
|
||||||
'warnings': self.warnings,
|
"source": "environment variable",
|
||||||
'values': values,
|
"errors": self.errors,
|
||||||
'options': {'multi_separator': ',',
|
"warnings": self.warnings,
|
||||||
'needs_convert': True,
|
"values": values,
|
||||||
|
"options": {
|
||||||
|
"multi_separator": ",",
|
||||||
|
"needs_convert": True,
|
||||||
},
|
},
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
variables = {}
|
variables = {}
|
||||||
|
|
@ -65,7 +71,9 @@ class RougailUserDataEnvironment:
|
||||||
variables.update(get_rougail_environment(option.name()))
|
variables.update(get_rougail_environment(option.name()))
|
||||||
else:
|
else:
|
||||||
return variables
|
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):
|
def get_rougail_environment(namespace, environment_name=None):
|
||||||
|
|
@ -77,11 +85,13 @@ def get_rougail_environment(namespace, environment_name=None):
|
||||||
"""
|
"""
|
||||||
# then we filter the ROUGAIL_ environment variables
|
# then we filter the ROUGAIL_ environment variables
|
||||||
if namespace is None:
|
if namespace is None:
|
||||||
rougail_environment_var = environment_name.upper() + '_'
|
rougail_environment_var = environment_name.upper() + "_"
|
||||||
len_env = len(rougail_environment_var)
|
len_env = len(rougail_environment_var)
|
||||||
else:
|
else:
|
||||||
rougail_environment_var = namespace.upper() + '.'
|
rougail_environment_var = namespace.upper() + "."
|
||||||
len_env = 0
|
len_env = 0
|
||||||
return {envvar[len_env:].lower(): envval
|
return {
|
||||||
|
envvar[len_env:].lower(): envval
|
||||||
for envvar, envval in os.environ.items()
|
for envvar, envval in os.environ.items()
|
||||||
if envvar.startswith(rougail_environment_var)}
|
if envvar.startswith(rougail_environment_var)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue