62 |
62 |
63 import sys |
63 import sys |
64 import traceback |
64 import traceback |
65 from StringIO import StringIO |
65 from StringIO import StringIO |
66 |
66 |
|
67 from six import add_metaclass |
|
68 |
67 from logilab.common import attrdict, shellutils |
69 from logilab.common import attrdict, shellutils |
68 from logilab.common.date import strptime |
70 from logilab.common.date import strptime |
69 from logilab.common.deprecation import deprecated, class_deprecated |
71 from logilab.common.deprecation import deprecated, class_deprecated |
70 |
72 |
71 from cubicweb import QueryError |
73 from cubicweb import QueryError |
114 if answer == 'abort': |
116 if answer == 'abort': |
115 sys.exit(1) |
117 sys.exit(1) |
116 return answer == 'Y' |
118 return answer == 'Y' |
117 |
119 |
118 |
120 |
|
121 @add_metaclass(class_deprecated) |
119 class catch_error(object): |
122 class catch_error(object): |
120 """Helper for @contextmanager decorator.""" |
123 """Helper for @contextmanager decorator.""" |
121 __metaclass__ = class_deprecated |
|
122 __deprecation_warning__ = '[3.21] deprecated' |
124 __deprecation_warning__ = '[3.21] deprecated' |
123 |
125 |
124 def __init__(self, ctl, key='unexpected error', msg=None): |
126 def __init__(self, ctl, key='unexpected error', msg=None): |
125 self.ctl = ctl |
127 self.ctl = ctl |
126 self.key = key |
128 self.key = key |
255 """Extract the keys that have more than one item in their bucket.""" |
257 """Extract the keys that have more than one item in their bucket.""" |
256 return [(k, len(v)) for k, v in buckets.items() |
258 return [(k, len(v)) for k, v in buckets.items() |
257 if k is not None and len(v) > 1] |
259 if k is not None and len(v) > 1] |
258 |
260 |
259 |
261 |
|
262 @add_metaclass(class_deprecated) |
260 class ObjectStore(object): |
263 class ObjectStore(object): |
261 """Store objects in memory for *faster* validation (development mode) |
264 """Store objects in memory for *faster* validation (development mode) |
262 |
265 |
263 But it will not enforce the constraints of the schema and hence will miss some problems |
266 But it will not enforce the constraints of the schema and hence will miss some problems |
264 |
267 |
265 >>> store = ObjectStore() |
268 >>> store = ObjectStore() |
266 >>> user = store.prepare_insert_entity('CWUser', login=u'johndoe') |
269 >>> user = store.prepare_insert_entity('CWUser', login=u'johndoe') |
267 >>> group = store.prepare_insert_entity('CWUser', name=u'unknown') |
270 >>> group = store.prepare_insert_entity('CWUser', name=u'unknown') |
268 >>> store.prepare_insert_relation(user, 'in_group', group) |
271 >>> store.prepare_insert_relation(user, 'in_group', group) |
269 """ |
272 """ |
270 __metaclass__ = class_deprecated |
|
271 __deprecation_warning__ = '[3.21] use the new importer API' |
273 __deprecation_warning__ = '[3.21] use the new importer API' |
272 |
274 |
273 def __init__(self): |
275 def __init__(self): |
274 self.items = [] |
276 self.items = [] |
275 self.eids = {} |
277 self.eids = {} |
336 @deprecated('[3.21] use prepare_insert_relation instead') |
338 @deprecated('[3.21] use prepare_insert_relation instead') |
337 def relate(self, eid_from, rtype, eid_to, **kwargs): |
339 def relate(self, eid_from, rtype, eid_to, **kwargs): |
338 self.prepare_insert_relation(eid_from, rtype, eid_to, **kwargs) |
340 self.prepare_insert_relation(eid_from, rtype, eid_to, **kwargs) |
339 |
341 |
340 |
342 |
|
343 @add_metaclass(class_deprecated) |
341 class CWImportController(object): |
344 class CWImportController(object): |
342 """Controller of the data import process. |
345 """Controller of the data import process. |
343 |
346 |
344 >>> ctl = CWImportController(store) |
347 >>> ctl = CWImportController(store) |
345 >>> ctl.generators = list_of_data_generators |
348 >>> ctl.generators = list_of_data_generators |
346 >>> ctl.data = dict_of_data_tables |
349 >>> ctl.data = dict_of_data_tables |
347 >>> ctl.run() |
350 >>> ctl.run() |
348 """ |
351 """ |
349 __metaclass__ = class_deprecated |
|
350 __deprecation_warning__ = '[3.21] use the new importer API' |
352 __deprecation_warning__ = '[3.21] use the new importer API' |
351 |
353 |
352 def __init__(self, store, askerror=0, catcherrors=None, tell=tell, |
354 def __init__(self, store, askerror=0, catcherrors=None, tell=tell, |
353 commitevery=50): |
355 commitevery=50): |
354 self.store = store |
356 self.store = store |