[entities] Move CWSource update_config method as a function in 3.15 migration script 3.25
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 05 Apr 2017 08:37:22 +0200
branch3.25
changeset 12133 8743c3bda480
parent 12132 be2c14ea2736
child 12134 0bf232be21a6
[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.
cubicweb/entities/sources.py
cubicweb/misc/migration/3.15.0_Any.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'
--- 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()