pre-commit, black, isort

This commit is contained in:
Stéphane Bidoul (ACSONE) 2019-11-12 16:46:39 +01:00 committed by Maxime Franco
parent d1a9ffcd8f
commit 6ee2098cfd
4 changed files with 18 additions and 57 deletions

View File

@ -181,18 +181,13 @@ class ServerEnvMixin(models.AbstractModel):
# _server_env_has_key_defined so we are sure that the value is
# either in the global or the record config
getter = getattr(serv_config, config_getter)
if (
section_name in serv_config
and field_name in serv_config[section_name]
):
if section_name in serv_config and field_name in serv_config[section_name]:
value = getter(section_name, field_name)
else:
value = getter(global_section_name, field_name)
except Exception:
_logger.exception(
"error trying to read field %s in section %s",
field_name,
section_name,
"error trying to read field %s in section %s", field_name, section_name
)
return False
return value
@ -206,8 +201,7 @@ class ServerEnvMixin(models.AbstractModel):
and field_name in serv_config[global_section_name]
)
has_config = (
section_name in serv_config
and field_name in serv_config[section_name]
section_name in serv_config and field_name in serv_config[section_name]
)
return has_global_config or has_config
@ -249,9 +243,7 @@ class ServerEnvMixin(models.AbstractModel):
record._compute_server_env_from_config(field_name, options)
else:
record._compute_server_env_from_default(
field_name, options
)
record._compute_server_env_from_default(field_name, options)
def _inverse_server_env(self, field_name):
options = self._server_env_fields[field_name]
@ -279,12 +271,8 @@ class ServerEnvMixin(models.AbstractModel):
# in ``_inverse_server_env`` it would reset the value of the field
for record in self:
for field_name in self._server_env_fields:
is_editable_field = self._server_env_is_editable_fieldname(
field_name
)
is_editable = not record._server_env_has_key_defined(
field_name
)
is_editable_field = self._server_env_is_editable_fieldname(field_name)
is_editable = not record._server_env_has_key_defined(field_name)
record[is_editable_field] = is_editable
def _server_env_view_set_readonly(self, view_arch):
@ -294,17 +282,12 @@ class ServerEnvMixin(models.AbstractModel):
for elem in view_arch.findall(field_xpath % field):
# set env-computed fields to readonly if the configuration
# files have a key set for this field
elem.set(
"attrs",
str({"readonly": [(is_editable_field, "=", False)]}),
)
elem.set("attrs", str({"readonly": [(is_editable_field, "=", False)]}))
if not view_arch.findall(field_xpath % is_editable_field):
# add the _is_editable fields in the view for the 'attrs'
# domain
view_arch.append(
etree.Element(
"field", name=is_editable_field, invisible="1"
)
etree.Element("field", name=is_editable_field, invisible="1")
)
return view_arch
@ -312,10 +295,7 @@ class ServerEnvMixin(models.AbstractModel):
self, view_id=None, view_type="form", toolbar=False, submenu=False
):
view_data = super()._fields_view_get(
view_id=view_id,
view_type=view_type,
toolbar=toolbar,
submenu=submenu,
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
)
view_arch = etree.fromstring(view_data["arch"].encode("utf-8"))
view_arch = self._server_env_view_set_readonly(view_arch)
@ -342,9 +322,7 @@ class ServerEnvMixin(models.AbstractModel):
field.compute = "_compute_server_env"
inverse_method_name = "_inverse_server_env_%s" % field.name
inverse_method = partialmethod(
type(self)._inverse_server_env, field.name
)
inverse_method = partialmethod(type(self)._inverse_server_env, field.name)
setattr(type(self), inverse_method_name, inverse_method)
field.inverse = inverse_method_name
field.store = False
@ -390,9 +368,7 @@ class ServerEnvMixin(models.AbstractModel):
base_field_cls = base_field.__class__
field_args = base_field.args.copy()
field_args.pop("_sequence", None)
field_args.update(
{"sparse": "server_env_defaults", "automatic": True}
)
field_args.update({"sparse": "server_env_defaults", "automatic": True})
if hasattr(base_field, "selection"):
field_args["selection"] = base_field.selection

View File

@ -38,8 +38,7 @@ try:
_dir = os.path.dirname(server_environment_files.__file__)
except ImportError:
_logger.info(
"not using server_environment_files for configuration,"
" no directory found"
"not using server_environment_files for configuration," " no directory found"
)
_dir = None
@ -120,9 +119,7 @@ def _load_config_from_server_env_files(config_p):
try:
config_p.read(conf_files)
except Exception as e:
raise Exception(
'Cannot read config files "{}": {}'.format(conf_files, e)
)
raise Exception('Cannot read config files "{}": {}'.format(conf_files, e))
def _load_config_from_rcfile(config_p):
@ -212,8 +209,7 @@ class ServerConfiguration(models.TransientModel):
ServerConfiguration,
col_name,
fields.Char(
string=cls._format_key_display_name(col_name),
readonly=True,
string=cls._format_key_display_name(col_name), readonly=True
),
)
cls._conf_defaults[col_name] = value
@ -257,10 +253,7 @@ class ServerConfiguration(models.TransientModel):
return (
'<group col="2" colspan="4">'
+ "".join(
[
'<field name="%s" readonly="1"/>' % _escape(name)
for name in names
]
['<field name="%s" readonly="1"/>' % _escape(name) for name in names]
)
+ "</group>"
)
@ -303,9 +296,7 @@ class ServerConfiguration(models.TransientModel):
View = self.env["ir.ui.view"]
if view_type == "form":
arch_node = self._arch
xarch, xfields = View.postprocess_and_fields(
self._name, arch_node, view_id
)
xarch, xfields = View.postprocess_and_fields(self._name, arch_node, view_id)
res["arch"] = xarch
res["fields"] = xfields
return res

View File

@ -30,11 +30,7 @@ from odoo.tools.config import config
def _get_output(cmd):
bindir = config["root_path"]
p = subprocess.Popen(
cmd,
shell=True,
cwd=bindir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cmd, shell=True, cwd=bindir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
return p.communicate()[0].rstrip()

View File

@ -47,9 +47,7 @@ class ServerEnvironmentCase(common.SavepointCase):
def load_config(self, public=None, secret=None):
original_serv_config = server_env_mixin.serv_config
try:
with self.set_config_dir(None), self.set_env_variables(
public, secret
):
with self.set_config_dir(None), self.set_env_variables(public, secret):
parser = server_env._load_config()
server_env_mixin.serv_config = parser
yield