15 class SourceAddedHook(SourceHook): |
15 class SourceAddedHook(SourceHook): |
16 __regid__ = 'cw.sources.added' |
16 __regid__ = 'cw.sources.added' |
17 __select__ = SourceHook.__select__ & is_instance('CWSource') |
17 __select__ = SourceHook.__select__ & is_instance('CWSource') |
18 events = ('after_add_entity',) |
18 events = ('after_add_entity',) |
19 def __call__(self): |
19 def __call__(self): |
20 if not self.entity.type in SOURCE_TYPES: |
20 try: |
|
21 sourcecls = SOURCE_TYPES[self.entity.type] |
|
22 except KeyError: |
21 msg = self._cw._('unknown source type') |
23 msg = self._cw._('unknown source type') |
22 raise ValidationError(self.entity.eid, |
24 raise ValidationError(self.entity.eid, |
23 {role_name('type', 'subject'): msg}) |
25 {role_name('type', 'subject'): msg}) |
|
26 sourcecls.check_conf_dict(self.entity.eid, self.entity.host_config, |
|
27 fail_if_unknown=not self._cw.vreg.config.repairing) |
24 SourceAddedOp(self._cw, entity=self.entity) |
28 SourceAddedOp(self._cw, entity=self.entity) |
25 |
29 |
26 |
30 |
27 class SourceRemovedOp(hook.Operation): |
31 class SourceRemovedOp(hook.Operation): |
28 def precommit_event(self): |
32 def precommit_event(self): |
34 events = ('before_delete_entity',) |
38 events = ('before_delete_entity',) |
35 def __call__(self): |
39 def __call__(self): |
36 if self.entity.name == 'system': |
40 if self.entity.name == 'system': |
37 raise ValidationError(self.entity.eid, {None: 'cant remove system source'}) |
41 raise ValidationError(self.entity.eid, {None: 'cant remove system source'}) |
38 SourceRemovedOp(self._cw, uri=self.entity.name) |
42 SourceRemovedOp(self._cw, uri=self.entity.name) |
|
43 |
|
44 |
|
45 class SourceUpdatedOp(hook.DataOperationMixIn, hook.Operation): |
|
46 |
|
47 def precommit_event(self): |
|
48 self.__processed = [] |
|
49 for source in self.get_data(): |
|
50 conf = source.repo_source.check_config(source) |
|
51 self.__processed.append( (source, conf) ) |
|
52 |
|
53 def postcommit_event(self): |
|
54 for source, conf in self.__processed: |
|
55 source.repo_source.update_config(source, conf) |
|
56 |
|
57 class SourceUpdatedHook(SourceHook): |
|
58 __regid__ = 'cw.sources.configupdate' |
|
59 __select__ = SourceHook.__select__ & is_instance('CWSource') |
|
60 events = ('after_update_entity',) |
|
61 def __call__(self): |
|
62 if 'config' in self.entity.cw_edited: |
|
63 SourceUpdatedOp.get_instance(self._cw).add_data(self.entity) |
|
64 |
|
65 class SourceHostConfigUpdatedHook(SourceHook): |
|
66 __regid__ = 'cw.sources.hostconfigupdate' |
|
67 __select__ = SourceHook.__select__ & is_instance('CWSourceHostConfig') |
|
68 events = ('after_add_entity', 'after_update_entity', 'before_delete_entity',) |
|
69 def __call__(self): |
|
70 try: |
|
71 SourceUpdatedOp.get_instance(self._cw).add_data(self.entity.cwsource) |
|
72 except IndexError: |
|
73 # XXX no source linked to the host config yet |
|
74 pass |
|
75 |
39 |
76 |
40 # source mapping synchronization. Expect cw_for_source/cw_schema are immutable |
77 # source mapping synchronization. Expect cw_for_source/cw_schema are immutable |
41 # relations (i.e. can't change from a source or schema to another). |
78 # relations (i.e. can't change from a source or schema to another). |
42 |
79 |
43 class SourceMappingDeleteHook(SourceHook): |
80 class SourceMappingDeleteHook(SourceHook): |