[entities] Move CWSource update_config method as a function in 3.15 migration script
This script is the only caller of this method. In the code of the function,
drop "skip_unknown" argument and continue accordingly upon OptionError.
--- a/cubicweb/entities/sources.py Wed Apr 05 10:34:04 2017 +0200
+++ b/cubicweb/entities/sources.py Wed Apr 05 08:37:22 2017 +0200
@@ -35,24 +35,6 @@
def dictconfig(self):
return self.config and text_to_dict(self.config) or {}
- def update_config(self, skip_unknown=False, **config):
- from cubicweb.server import SOURCE_TYPES
- from cubicweb.server.serverconfig import (SourceConfiguration,
- generate_source_config)
- cfg = self.dictconfig
- cfg.update(config)
- options = SOURCE_TYPES[self.type].options
- sconfig = SourceConfiguration(self._cw.vreg.config, options=options)
- for opt, val in cfg.items():
- try:
- sconfig.set_option(opt, val)
- except OptionError:
- if skip_unknown:
- continue
- raise
- cfgstr = text_type(generate_source_config(sconfig), self._cw.encoding)
- self.cw_set(config=cfgstr)
-
class CWSource(_CWSourceCfgMixIn, AnyEntity):
__regid__ = 'CWSource'
--- a/cubicweb/misc/migration/3.15.0_Any.py Wed Apr 05 10:34:04 2017 +0200
+++ b/cubicweb/misc/migration/3.15.0_Any.py Wed Apr 05 08:37:22 2017 +0200
@@ -1,10 +1,30 @@
+from cubicweb.server import SOURCE_TYPES
+from cubicweb.server.serverconfig import (SourceConfiguration,
+ generate_source_config)
+
+
sync_schema_props_perms('EmailAddress')
+
+def update_config(source, **config):
+ cfg = source.dictconfig
+ cfg.update(config)
+ options = SOURCE_TYPES[source.type].options
+ sconfig = SourceConfiguration(source._cw.vreg.config, options=options)
+ for opt, val in cfg.items():
+ try:
+ sconfig.set_option(opt, val)
+ except OptionError:
+ continue
+ cfgstr = text_type(generate_source_config(sconfig), source._cw.encoding)
+ source.cw_set(config=cfgstr)
+
+
for source in rql('CWSource X WHERE X type "ldapuser"').entities():
config = source.dictconfig
host = config.pop('host', u'ldap')
protocol = config.pop('protocol', u'ldap')
source.cw_set(url=u'%s://%s' % (protocol, host))
- source.update_config(skip_unknown=True, **config)
+ update_config(source, **config)
commit()