cubicweb/misc/migration/3.15.0_Any.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 15 Mar 2019 12:12:23 +0100
changeset 12523 4d68d20427de
parent 12133 8743c3bda480
child 12567 26744ad37953
permissions -rw-r--r--
Skip tests for ldapsource with python >= 3.7 Until someone works on fixing these, this should make our CI green again. I tried to use setupModule() to check for python version, but pre_setup_database() is apparently called even when a SkipTest exception is raised there. So handle this in that method.

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))
    update_config(source, **config)

commit()