# HG changeset patch # User Denis Laxalde # Date 1491374242 -7200 # Node ID 8743c3bda480585cabd2955475711de7fbc5ce49 # Parent be2c14ea2736a045f517dc4fb170c6874c53ec0f [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. diff -r be2c14ea2736 -r 8743c3bda480 cubicweb/entities/sources.py --- 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' diff -r be2c14ea2736 -r 8743c3bda480 cubicweb/misc/migration/3.15.0_Any.py --- 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()