[dataio] provide compatibility with CW 3.19 (closes #279602)

config.sources() doesn't exist anymore in CW 3.19, we should use the config.default_admin_config dictionary instead.

authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
changeset010d03707a5f
branchdefault
phasepublic
hiddenno
parent revision#afd0c31334e2 fix NameError (s/query/rql) in dataio.rqlquery (closes #279601)
child revision#eb99225b4167 [debian] recommend python-dateutil (closes #279605)
files modified by this revision
utils/dataio.py
# HG changeset patch
# User Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
# Date 1416819986 -3600
# Mon Nov 24 10:06:26 2014 +0100
# Node ID 010d03707a5ff3c85c1e39581c16901e55bfcaf4
# Parent afd0c31334e259309501f2e7facf9bc7ef46cc35
[dataio] provide compatibility with CW 3.19 (closes #279602)

``config.sources()`` doesn't exist anymore in CW 3.19, we should
use the ``config.default_admin_config`` dictionary instead.

diff --git a/utils/dataio.py b/utils/dataio.py
@@ -55,15 +55,19 @@
1  ###############################################################################
2  def get_cw_cnx(endpoint):
3      """ Get a cnx on a CubicWeb database
4      """
5      from cubicweb import dbapi
6 +    from cubicweb.__pkginfo__ import numversion
7      from cubicweb.cwconfig import CubicWebConfiguration
8      from cubicweb.entities import AnyEntity
9      CubicWebConfiguration.load_cwctl_plugins()
10      config = CubicWebConfiguration.config_for(endpoint)
11 -    sourceinfo = config.sources()['admin']
12 +    if numversion < (3, 19):
13 +        sourceinfo = config.sources()['admin']
14 +    else:
15 +        sourceinfo = config.default_admin_config
16      login = sourceinfo['login']
17      password = sourceinfo['password']
18      _, cnx = dbapi.in_memory_repo_cnx(config, login, password=password)
19      req = cnx.request()
20      return req