author | Rémi Cardona <remi.cardona@logilab.fr> |
Fri, 18 Sep 2015 11:58:29 +0200 | |
changeset 10707 | 3f4f190f8e35 |
parent 10651 | 9ca33768473c |
child 10832 | 2350424585f8 |
permissions | -rw-r--r-- |
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
1 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5124
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5824 | 18 |
"""cubicweb server sources support""" |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
19 |
from __future__ import print_function |
0 | 20 |
|
21 |
__docformat__ = "restructuredtext en" |
|
22 |
||
9180
13ed6de41774
[querier] Add timings to debug prints (DBG_RQL)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8892
diff
changeset
|
23 |
from time import time |
0 | 24 |
from logging import getLogger |
10580
5fbdbbe51867
[server/sources] add decode_extid method
Julien Cristau <julien.cristau@logilab.fr>
parents:
10086
diff
changeset
|
25 |
from base64 import b64decode |
0 | 26 |
|
10622
3cc6154b94a3
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10589
diff
changeset
|
27 |
from six import text_type |
0 | 28 |
|
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
29 |
from logilab.common import configuration |
7697
ef50074a0314
[repo api] deprecates source.extid2eid, only the system source should implement it,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7552
diff
changeset
|
30 |
from logilab.common.deprecation import deprecated |
0 | 31 |
|
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
32 |
from yams.schema import role_name |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
33 |
|
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
34 |
from cubicweb import ValidationError, set_log_methods, server |
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
35 |
from cubicweb.server import SOURCE_TYPES |
7118
e094b3d4eb95
[server] move EditedEntity class to its own module, to avoid cyclic dependency when needed from e.g. session.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7040
diff
changeset
|
36 |
from cubicweb.server.edition import EditedEntity |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1250
diff
changeset
|
37 |
|
0 | 38 |
|
2625
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
39 |
def dbg_st_search(uri, union, varmap, args, cachekey=None, prefix='rql for'): |
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
40 |
if server.DEBUG & server.DBG_RQL: |
9180
13ed6de41774
[querier] Add timings to debug prints (DBG_RQL)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8892
diff
changeset
|
41 |
global t |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
42 |
print(' %s %s source: %s' % (prefix, uri, repr(union.as_string()))) |
9180
13ed6de41774
[querier] Add timings to debug prints (DBG_RQL)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8892
diff
changeset
|
43 |
t = time() |
2625
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
44 |
if varmap: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
45 |
print(' using varmap', varmap) |
2625
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
46 |
if server.DEBUG & server.DBG_MORE: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
47 |
print(' args', repr(args)) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
48 |
print(' cache key', cachekey) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
49 |
print(' solutions', ','.join(str(s.solutions) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
50 |
for s in union.children)) |
2625
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
51 |
# return true so it can be used as assertion (and so be killed by python -O) |
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
52 |
return True |
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
53 |
|
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
54 |
def dbg_results(results): |
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
55 |
if server.DEBUG & server.DBG_RQL: |
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
56 |
if len(results) > 10: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
57 |
print(' -->', results[:10], '...', len(results), end=' ') |
2625
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
58 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
59 |
print(' -->', results, end=' ') |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10580
diff
changeset
|
60 |
print('time: ', time() - t) |
2625
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
61 |
# return true so it can be used as assertion (and so be killed by python -O) |
d6012db7b93e
R [server debug] more server side debugging tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
62 |
return True |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
63 |
|
0 | 64 |
|
65 |
class AbstractSource(object): |
|
66 |
"""an abstract class for sources""" |
|
67 |
||
68 |
# boolean telling if modification hooks should be called when something is |
|
69 |
# modified in this source |
|
70 |
should_call_hooks = True |
|
71 |
# boolean telling if the repository should connect to this source during |
|
72 |
# migration |
|
73 |
connect_for_migration = True |
|
1792 | 74 |
|
0 | 75 |
# mappings telling which entities and relations are available in the source |
76 |
# keys are supported entity/relation types and values are boolean indicating |
|
77 |
# wether the support is read-only (False) or read-write (True) |
|
78 |
support_entities = {} |
|
79 |
support_relations = {} |
|
80 |
# a global identifier for this source, which has to be set by the source |
|
81 |
# instance |
|
82 |
uri = None |
|
83 |
# a reference to the system information helper |
|
84 |
repo = None |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
85 |
# a reference to the instance'schema (may differs from the source'schema) |
0 | 86 |
schema = None |
1792 | 87 |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
88 |
# force deactivation (configuration error for instance) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
89 |
disabled = False |
3040
e4dc22040f5f
[multi-sources] move [dont_]cross_relations to AbstractSource
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2759
diff
changeset
|
90 |
|
7552
82dde8276a5b
[datafeed, entities] url for entities from a datafeed source should be on their origin site. Closes #1769391
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
91 |
# boolean telling if cwuri of entities from this source is the url that |
82dde8276a5b
[datafeed, entities] url for entities from a datafeed source should be on their origin site. Closes #1769391
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
92 |
# should be used as entity's absolute url |
82dde8276a5b
[datafeed, entities] url for entities from a datafeed source should be on their origin site. Closes #1769391
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
93 |
use_cwuri_as_url = False |
82dde8276a5b
[datafeed, entities] url for entities from a datafeed source should be on their origin site. Closes #1769391
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
94 |
|
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
95 |
# source configuration options |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
96 |
options = () |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
97 |
|
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
98 |
# these are overridden by set_log_methods below |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
99 |
# only defining here to prevent pylint from complaining |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
100 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
101 |
|
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
102 |
def __init__(self, repo, source_config, eid=None): |
0 | 103 |
self.repo = repo |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
104 |
self.set_schema(repo.schema) |
0 | 105 |
self.support_relations['identity'] = False |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
106 |
self.eid = eid |
6722
3341521d857b
[repo source] rename attribute so it's much easier to grasp its role
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
107 |
self.public_config = source_config.copy() |
9822
4a118bfd6ab4
[datafeed] Allow to override use_cwuri_as_url in configuration of a datafeed source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9662
diff
changeset
|
108 |
self.public_config['use-cwuri-as-url'] = self.use_cwuri_as_url |
6722
3341521d857b
[repo source] rename attribute so it's much easier to grasp its role
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
109 |
self.remove_sensitive_information(self.public_config) |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
110 |
self.uri = source_config.pop('uri') |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
111 |
set_log_methods(self, getLogger('cubicweb.sources.'+self.uri)) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
112 |
source_config.pop('type') |
8674
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
113 |
self.update_config(None, self.check_conf_dict(eid, source_config, |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
114 |
fail_if_unknown=False)) |
1792 | 115 |
|
0 | 116 |
def __repr__(self): |
8228
fe53c7e1625f
[sources] include source's class in its repr
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8134
diff
changeset
|
117 |
return '<%s %s source %s @%#x>' % (self.uri, self.__class__.__name__, |
fe53c7e1625f
[sources] include source's class in its repr
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8134
diff
changeset
|
118 |
self.eid, id(self)) |
0 | 119 |
|
8892
80783605d270
[toward-py3k] rewrite __cmp__ (closes #2715115)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8696
diff
changeset
|
120 |
def __lt__(self, other): |
0 | 121 |
"""simple comparison function to get predictable source order, with the |
122 |
system source at last |
|
123 |
""" |
|
124 |
if self.uri == other.uri: |
|
8892
80783605d270
[toward-py3k] rewrite __cmp__ (closes #2715115)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8696
diff
changeset
|
125 |
return False |
0 | 126 |
if self.uri == 'system': |
8892
80783605d270
[toward-py3k] rewrite __cmp__ (closes #2715115)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8696
diff
changeset
|
127 |
return False |
0 | 128 |
if other.uri == 'system': |
8892
80783605d270
[toward-py3k] rewrite __cmp__ (closes #2715115)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8696
diff
changeset
|
129 |
return True |
80783605d270
[toward-py3k] rewrite __cmp__ (closes #2715115)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8696
diff
changeset
|
130 |
return self.uri < other.uri |
80783605d270
[toward-py3k] rewrite __cmp__ (closes #2715115)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8696
diff
changeset
|
131 |
|
80783605d270
[toward-py3k] rewrite __cmp__ (closes #2715115)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8696
diff
changeset
|
132 |
def __eq__(self, other): |
80783605d270
[toward-py3k] rewrite __cmp__ (closes #2715115)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8696
diff
changeset
|
133 |
return self.uri == other.uri |
1792 | 134 |
|
10576
1ee631aedf2f
[server/sources] AbstractSource.__ne__
Julien Cristau <julien.cristau@logilab.fr>
parents:
10575
diff
changeset
|
135 |
def __ne__(self, other): |
1ee631aedf2f
[server/sources] AbstractSource.__ne__
Julien Cristau <julien.cristau@logilab.fr>
parents:
10575
diff
changeset
|
136 |
return not (self == other) |
1ee631aedf2f
[server/sources] AbstractSource.__ne__
Julien Cristau <julien.cristau@logilab.fr>
parents:
10575
diff
changeset
|
137 |
|
7342
d1c8b5b3531c
adds support for a portable db import/export format (closes: #1521112)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7237
diff
changeset
|
138 |
def backup(self, backupfile, confirm, format='native'): |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
139 |
"""method called to create a backup of source's data""" |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
140 |
pass |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
141 |
|
7342
d1c8b5b3531c
adds support for a portable db import/export format (closes: #1521112)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7237
diff
changeset
|
142 |
def restore(self, backupfile, confirm, drop, format='native'): |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
143 |
"""method called to restore a backup of source's data""" |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
144 |
pass |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
145 |
|
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
146 |
@classmethod |
10622
3cc6154b94a3
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10589
diff
changeset
|
147 |
def check_conf_dict(cls, eid, confdict, _=text_type, fail_if_unknown=True): |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
148 |
"""check configuration of source entity. Return config dict properly |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
149 |
typed with defaults set. |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
150 |
""" |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
151 |
processed = {} |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
152 |
for optname, optdict in cls.options: |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
153 |
value = confdict.pop(optname, optdict.get('default')) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
154 |
if value is configuration.REQUIRED: |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
155 |
if not fail_if_unknown: |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
156 |
continue |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
157 |
msg = _('specifying %s is mandatory' % optname) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
158 |
raise ValidationError(eid, {role_name('config', 'subject'): msg}) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
159 |
elif value is not None: |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
160 |
# type check |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
161 |
try: |
9292
4b3e657d17ab
[source configuration] silent lgc 0.60 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9180
diff
changeset
|
162 |
value = configuration._validate(value, optdict, optname) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8674
diff
changeset
|
163 |
except Exception as ex: |
10622
3cc6154b94a3
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10589
diff
changeset
|
164 |
msg = text_type(ex) # XXX internationalization |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
165 |
raise ValidationError(eid, {role_name('config', 'subject'): msg}) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
166 |
processed[optname] = value |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
167 |
# cw < 3.10 bw compat |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
168 |
try: |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
169 |
processed['adapter'] = confdict['adapter'] |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7779
diff
changeset
|
170 |
except KeyError: |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
171 |
pass |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
172 |
# check for unknown options |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
173 |
if confdict and tuple(confdict) != ('adapter',): |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
174 |
if fail_if_unknown: |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
175 |
msg = _('unknown options %s') % ', '.join(confdict) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
176 |
raise ValidationError(eid, {role_name('config', 'subject'): msg}) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
177 |
else: |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
178 |
logger = getLogger('cubicweb.sources') |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
179 |
logger.warning('unknown options %s', ', '.join(confdict)) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
180 |
# add options to processed, they may be necessary during migration |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
181 |
processed.update(confdict) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
182 |
return processed |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
183 |
|
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
184 |
@classmethod |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
185 |
def check_config(cls, source_entity): |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
186 |
"""check configuration of source entity""" |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
187 |
return cls.check_conf_dict(source_entity.eid, source_entity.host_config, |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
188 |
_=source_entity._cw._) |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
189 |
|
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
190 |
def update_config(self, source_entity, typedconfig): |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
191 |
"""update configuration from source entity. `typedconfig` is config |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
192 |
properly typed with defaults set |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
193 |
""" |
8674
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
194 |
if source_entity is not None: |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
195 |
self._entity_update(source_entity) |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
196 |
self.config = typedconfig |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
197 |
|
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
198 |
def _entity_update(self, source_entity): |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
199 |
source_entity.complete() |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
200 |
if source_entity.url: |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
201 |
self.urls = [url.strip() for url in source_entity.url.splitlines() |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
202 |
if url.strip()] |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
203 |
else: |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
204 |
self.urls = [] |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
205 |
|
10580
5fbdbbe51867
[server/sources] add decode_extid method
Julien Cristau <julien.cristau@logilab.fr>
parents:
10086
diff
changeset
|
206 |
@staticmethod |
5fbdbbe51867
[server/sources] add decode_extid method
Julien Cristau <julien.cristau@logilab.fr>
parents:
10086
diff
changeset
|
207 |
def decode_extid(extid): |
5fbdbbe51867
[server/sources] add decode_extid method
Julien Cristau <julien.cristau@logilab.fr>
parents:
10086
diff
changeset
|
208 |
if extid is None: |
5fbdbbe51867
[server/sources] add decode_extid method
Julien Cristau <julien.cristau@logilab.fr>
parents:
10086
diff
changeset
|
209 |
return extid |
5fbdbbe51867
[server/sources] add decode_extid method
Julien Cristau <julien.cristau@logilab.fr>
parents:
10086
diff
changeset
|
210 |
return b64decode(extid) |
5fbdbbe51867
[server/sources] add decode_extid method
Julien Cristau <julien.cristau@logilab.fr>
parents:
10086
diff
changeset
|
211 |
|
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
212 |
# source initialization / finalization ##################################### |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
213 |
|
0 | 214 |
def set_schema(self, schema): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
215 |
"""set the instance'schema""" |
0 | 216 |
self.schema = schema |
1792 | 217 |
|
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
218 |
def init_creating(self): |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
219 |
"""method called by the repository once ready to create a new instance""" |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
220 |
pass |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
221 |
|
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6945
diff
changeset
|
222 |
def init(self, activated, source_entity): |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
223 |
"""method called by the repository once ready to handle request. |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
224 |
`activated` is a boolean flag telling if the source is activated or not. |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
225 |
""" |
8674
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
226 |
if activated: |
001c1592060a
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
227 |
self._entity_update(source_entity) |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
228 |
|
7552
82dde8276a5b
[datafeed, entities] url for entities from a datafeed source should be on their origin site. Closes #1769391
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
229 |
PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url') |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
230 |
def remove_sensitive_information(self, sourcedef): |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
231 |
"""remove sensitive information such as login / password from source |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
232 |
definition |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
233 |
""" |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
234 |
for key in list(sourcedef): |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
235 |
if not key in self.PUBLIC_KEYS: |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
236 |
sourcedef.pop(key) |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
237 |
|
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
238 |
# connections handling ##################################################### |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
239 |
|
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
240 |
def get_connection(self): |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
241 |
"""open and return a connection to the source""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
242 |
raise NotImplementedError(self) |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
243 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7342
diff
changeset
|
244 |
def close_source_connections(self): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7342
diff
changeset
|
245 |
for cnxset in self.repo.cnxsets: |
9463
d62e13eba033
[multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
246 |
cnxset.cu = None |
d62e13eba033
[multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
247 |
cnxset.cnx.close() |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
248 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7342
diff
changeset
|
249 |
def open_source_connections(self): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7342
diff
changeset
|
250 |
for cnxset in self.repo.cnxsets: |
9463
d62e13eba033
[multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
251 |
cnxset.cnx = self.get_connection() |
d62e13eba033
[multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
252 |
cnxset.cu = cnxset.cnx.cursor() |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
253 |
|
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
254 |
# cache handling ########################################################### |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
255 |
|
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
256 |
def reset_caches(self): |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
257 |
"""method called during test to reset potential source caches""" |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
258 |
pass |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
259 |
|
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
260 |
def clear_eid_cache(self, eid, etype): |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
261 |
"""clear potential caches for the given eid""" |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
262 |
pass |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
263 |
|
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
264 |
# external source api ###################################################### |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
265 |
|
0 | 266 |
def support_entity(self, etype, write=False): |
267 |
"""return true if the given entity's type is handled by this adapter |
|
268 |
if write is true, return true only if it's a RW support |
|
269 |
""" |
|
270 |
try: |
|
271 |
wsupport = self.support_entities[etype] |
|
272 |
except KeyError: |
|
273 |
return False |
|
274 |
if write: |
|
275 |
return wsupport |
|
276 |
return True |
|
1792 | 277 |
|
0 | 278 |
def support_relation(self, rtype, write=False): |
279 |
"""return true if the given relation's type is handled by this adapter |
|
280 |
if write is true, return true only if it's a RW support |
|
281 |
||
1792 | 282 |
current implementation return true if the relation is defined into |
283 |
`support_relations` or if it is a final relation of a supported entity |
|
0 | 284 |
type |
285 |
""" |
|
286 |
try: |
|
287 |
wsupport = self.support_relations[rtype] |
|
288 |
except KeyError: |
|
289 |
rschema = self.schema.rschema(rtype) |
|
6057
cb5c8852cbda
[ms] cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5849
diff
changeset
|
290 |
if not rschema.final or rschema.type == 'has_text': |
0 | 291 |
return False |
292 |
for etype in rschema.subjects(): |
|
293 |
try: |
|
294 |
wsupport = self.support_entities[etype] |
|
295 |
break |
|
296 |
except KeyError: |
|
297 |
continue |
|
298 |
else: |
|
299 |
return False |
|
300 |
if write: |
|
301 |
return wsupport |
|
1792 | 302 |
return True |
303 |
||
9620
7b7d5a5d6365
[server/sources] {before,after}_entity_insertion wants a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9543
diff
changeset
|
304 |
def before_entity_insertion(self, cnx, lid, etype, eid, sourceparams): |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
305 |
"""called by the repository when an eid has been attributed for an |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
306 |
entity stored here but the entity has not been inserted in the system |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
307 |
table yet. |
0 | 308 |
|
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
309 |
This method must return the an Entity instance representation of this |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
310 |
entity. |
0 | 311 |
""" |
9620
7b7d5a5d6365
[server/sources] {before,after}_entity_insertion wants a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9543
diff
changeset
|
312 |
entity = self.repo.vreg['etypes'].etype_class(etype)(cnx) |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
313 |
entity.eid = eid |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
314 |
entity.cw_edited = EditedEntity(entity) |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
315 |
return entity |
1792 | 316 |
|
9620
7b7d5a5d6365
[server/sources] {before,after}_entity_insertion wants a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9543
diff
changeset
|
317 |
def after_entity_insertion(self, cnx, lid, entity, sourceparams): |
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
318 |
"""called by the repository after an entity stored here has been |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
319 |
inserted in the system table. |
0 | 320 |
""" |
321 |
pass |
|
1792 | 322 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
323 |
def _load_mapping(self, cnx, **kwargs): |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6945
diff
changeset
|
324 |
if not 'CWSourceSchemaConfig' in self.schema: |
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6945
diff
changeset
|
325 |
self.warning('instance is not mapping ready') |
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6945
diff
changeset
|
326 |
return |
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
327 |
for schemacfg in cnx.execute( |
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
328 |
'Any CFG,CFGO,S WHERE ' |
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
329 |
'CFG options CFGO, CFG cw_schema S, ' |
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
330 |
'CFG cw_for_source X, X eid %(x)s', {'x': self.eid}).entities(): |
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
331 |
self.add_schema_config(schemacfg, **kwargs) |
0 | 332 |
|
6944
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
333 |
def add_schema_config(self, schemacfg, checkonly=False): |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
334 |
"""added CWSourceSchemaConfig, modify mapping accordingly""" |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
335 |
msg = schemacfg._cw._("this source doesn't use a mapping") |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
336 |
raise ValidationError(schemacfg.eid, {None: msg}) |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
337 |
|
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
338 |
def del_schema_config(self, schemacfg, checkonly=False): |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
339 |
"""deleted CWSourceSchemaConfig, modify mapping accordingly""" |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
340 |
msg = schemacfg._cw._("this source doesn't use a mapping") |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
341 |
raise ValidationError(schemacfg.eid, {None: msg}) |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
342 |
|
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
343 |
def update_schema_config(self, schemacfg, checkonly=False): |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
344 |
"""updated CWSourceSchemaConfig, modify mapping accordingly""" |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
345 |
self.del_schema_config(schemacfg, checkonly) |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
346 |
self.add_schema_config(schemacfg, checkonly) |
0cf10429ad39
[sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6943
diff
changeset
|
347 |
|
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
348 |
# user authentication api ################################################## |
1792 | 349 |
|
9512
88dc96fc9fc1
[server] use a connection instead of a session for user authentication
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
350 |
def authenticate(self, cnx, login, **kwargs): |
6152
6824f8b61098
use is_instance in a number of places (esp. documentation) rather than the deprecated implements
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6057
diff
changeset
|
351 |
"""if the source support CWUser entity type, it should implement |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
352 |
this method which should return CWUser eid for the given login/password |
0 | 353 |
if this account is defined in this source and valid login / password is |
354 |
given. Else raise `AuthenticationError` |
|
355 |
""" |
|
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
356 |
raise NotImplementedError(self) |
1792 | 357 |
|
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
358 |
# RQL query api ############################################################ |
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
359 |
|
9512
88dc96fc9fc1
[server] use a connection instead of a session for user authentication
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
360 |
def syntax_tree_search(self, cnx, union, |
0 | 361 |
args=None, cachekey=None, varmap=None, debug=0): |
1792 | 362 |
"""return result from this source for a rql query (actually from a rql |
363 |
syntax tree and a solution dictionary mapping each used variable to a |
|
0 | 364 |
possible type). If cachekey is given, the query necessary to fetch the |
365 |
results (but not the results themselves) may be cached using this key. |
|
366 |
""" |
|
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
367 |
raise NotImplementedError(self) |
1792 | 368 |
|
6943
406a41c25e13
[sources] reorganize abstract source code, drop no more used cleanup_entities_info and _cleanup_system_relations methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
369 |
# write modification api ################################################### |
0 | 370 |
# read-only sources don't have to implement methods below |
371 |
||
372 |
def get_extid(self, entity): |
|
373 |
"""return the external id for the given newly inserted entity""" |
|
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
374 |
raise NotImplementedError(self) |
1792 | 375 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
376 |
def add_entity(self, cnx, entity): |
0 | 377 |
"""add a new entity to the source""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
378 |
raise NotImplementedError(self) |
1792 | 379 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
380 |
def update_entity(self, cnx, entity): |
0 | 381 |
"""update an entity in the source""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
382 |
raise NotImplementedError(self) |
0 | 383 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
384 |
def delete_entities(self, cnx, entities): |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6722
diff
changeset
|
385 |
"""delete several entities from the source""" |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6722
diff
changeset
|
386 |
for entity in entities: |
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
387 |
self.delete_entity(cnx, entity) |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6722
diff
changeset
|
388 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
389 |
def delete_entity(self, cnx, entity): |
0 | 390 |
"""delete an entity from the source""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
391 |
raise NotImplementedError(self) |
0 | 392 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
393 |
def add_relation(self, cnx, subject, rtype, object): |
0 | 394 |
"""add a relation to the source""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
395 |
raise NotImplementedError(self) |
1792 | 396 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
397 |
def add_relations(self, cnx, rtype, subj_obj_list): |
7237
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7118
diff
changeset
|
398 |
"""add a relations to the source""" |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7118
diff
changeset
|
399 |
# override in derived classes if you feel you can |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7118
diff
changeset
|
400 |
# optimize |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7118
diff
changeset
|
401 |
for subject, object in subj_obj_list: |
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
402 |
self.add_relation(cnx, subject, rtype, object) |
7237
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7118
diff
changeset
|
403 |
|
0 | 404 |
def delete_relation(self, session, subject, rtype, object): |
405 |
"""delete a relation from the source""" |
|
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
406 |
raise NotImplementedError(self) |
0 | 407 |
|
408 |
# system source interface ################################################# |
|
409 |
||
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
410 |
def eid_type_source(self, cnx, eid): |
10575
036f5964e6fe
[server/sources] fix docstring for eid_type_source
Julien Cristau <julien.cristau@logilab.fr>
parents:
10086
diff
changeset
|
411 |
"""return a tuple (type, extid, source) for the entity with id <eid>""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
412 |
raise NotImplementedError(self) |
1792 | 413 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
414 |
def create_eid(self, cnx): |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
415 |
raise NotImplementedError(self) |
0 | 416 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
417 |
def add_info(self, cnx, entity, source, extid): |
0 | 418 |
"""add type and source info for an eid into the system table""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
419 |
raise NotImplementedError(self) |
0 | 420 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
421 |
def update_info(self, cnx, entity, need_fti_update): |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4807
diff
changeset
|
422 |
"""mark entity as being modified, fulltext reindex if needed""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
423 |
raise NotImplementedError(self) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4807
diff
changeset
|
424 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
425 |
def index_entity(self, cnx, entity): |
4807
5642bfa43236
[cleanup] add index_entity to abstract source, add docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
426 |
"""create an operation to [re]index textual content of the given entity |
5642bfa43236
[cleanup] add index_entity to abstract source, add docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
427 |
on commit |
5642bfa43236
[cleanup] add index_entity to abstract source, add docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
428 |
""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
429 |
raise NotImplementedError(self) |
4807
5642bfa43236
[cleanup] add index_entity to abstract source, add docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
430 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
431 |
def fti_unindex_entities(self, cnx, entities): |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6722
diff
changeset
|
432 |
"""remove text content for entities from the full text index |
0 | 433 |
""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
434 |
raise NotImplementedError(self) |
1792 | 435 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
436 |
def fti_index_entities(self, cnx, entities): |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6722
diff
changeset
|
437 |
"""add text content of created/modified entities to the full text index |
0 | 438 |
""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
439 |
raise NotImplementedError(self) |
1792 | 440 |
|
0 | 441 |
# sql system source interface ############################################# |
442 |
||
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
443 |
def sqlexec(self, cnx, sql, args=None): |
0 | 444 |
"""execute the query and return its result""" |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
445 |
raise NotImplementedError(self) |
1792 | 446 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
447 |
def create_index(self, cnx, table, column, unique=False): |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
448 |
raise NotImplementedError(self) |
1792 | 449 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
450 |
def drop_index(self, cnx, table, column, unique=False): |
8134
7f93da785e3a
add instance to not implemented error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7922
diff
changeset
|
451 |
raise NotImplementedError(self) |
0 | 452 |
|
7697
ef50074a0314
[repo api] deprecates source.extid2eid, only the system source should implement it,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7552
diff
changeset
|
453 |
|
10086
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
454 |
@deprecated('[3.13] use extid2eid(source, value, etype, cnx, **kwargs)') |
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
455 |
def extid2eid(self, value, etype, cnx, **kwargs): |
98bc2ca1a816
[source/native] session -> cnx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9822
diff
changeset
|
456 |
return self.repo.extid2eid(self, value, etype, cnx, **kwargs) |
7697
ef50074a0314
[repo api] deprecates source.extid2eid, only the system source should implement it,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7552
diff
changeset
|
457 |
|
ef50074a0314
[repo api] deprecates source.extid2eid, only the system source should implement it,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7552
diff
changeset
|
458 |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
459 |
|
0 | 460 |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
461 |
def source_adapter(source_type): |
0 | 462 |
try: |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
463 |
return SOURCE_TYPES[source_type] |
0 | 464 |
except KeyError: |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
465 |
raise RuntimeError('Unknown source type %r' % source_type) |
1792 | 466 |
|
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
467 |
def get_source(type, source_config, repo, eid): |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
468 |
"""return a source adapter according to the adapter field in the source's |
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
469 |
configuration |
0 | 470 |
""" |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6944
diff
changeset
|
471 |
return source_adapter(type)(repo, source_config, eid) |