45 events = ('after_add_entity',) |
45 events = ('after_add_entity',) |
46 def __call__(self): |
46 def __call__(self): |
47 try: |
47 try: |
48 sourcecls = SOURCE_TYPES[self.entity.type] |
48 sourcecls = SOURCE_TYPES[self.entity.type] |
49 except KeyError: |
49 except KeyError: |
50 msg = _('unknown source type') |
50 msg = _('Unknown source type') |
51 raise validation_error(self.entity, {('type', 'subject'): msg}) |
51 raise validation_error(self.entity, {('type', 'subject'): msg}) |
52 sourcecls.check_conf_dict(self.entity.eid, self.entity.host_config, |
52 # ignore creation of the system source done during database |
53 fail_if_unknown=not self._cw.vreg.config.repairing) |
53 # initialisation, as config for this source is in a file and handling |
54 SourceAddedOp(self._cw, entity=self.entity) |
54 # is done separatly (no need for the operation either) |
|
55 if self.entity.name != 'system': |
|
56 sourcecls.check_conf_dict(self.entity.eid, self.entity.host_config, |
|
57 fail_if_unknown=not self._cw.vreg.config.repairing) |
|
58 SourceAddedOp(self._cw, entity=self.entity) |
55 |
59 |
56 |
60 |
57 class SourceRemovedOp(hook.Operation): |
61 class SourceRemovedOp(hook.Operation): |
58 uri = None # make pylint happy |
62 uri = None # make pylint happy |
59 def postcommit_event(self): |
63 def postcommit_event(self): |
115 class SourceUpdatedHook(SourceHook): |
119 class SourceUpdatedHook(SourceHook): |
116 __regid__ = 'cw.sources.configupdate' |
120 __regid__ = 'cw.sources.configupdate' |
117 __select__ = SourceHook.__select__ & is_instance('CWSource') |
121 __select__ = SourceHook.__select__ & is_instance('CWSource') |
118 events = ('before_update_entity',) |
122 events = ('before_update_entity',) |
119 def __call__(self): |
123 def __call__(self): |
120 if 'config' in self.entity.cw_edited: |
|
121 SourceConfigUpdatedOp.get_instance(self._cw).add_data(self.entity) |
|
122 if 'name' in self.entity.cw_edited: |
124 if 'name' in self.entity.cw_edited: |
123 oldname, newname = self.entity.cw_edited.oldnewvalue('name') |
125 oldname, newname = self.entity.cw_edited.oldnewvalue('name') |
|
126 if oldname == 'system': |
|
127 msg = _("You cannot rename the system source") |
|
128 raise validation_error(self.entity, {('name', 'subject'): msg}) |
124 SourceRenamedOp(self._cw, oldname=oldname, newname=newname) |
129 SourceRenamedOp(self._cw, oldname=oldname, newname=newname) |
|
130 if 'config' in self.entity.cw_edited: |
|
131 if self.entity.name == 'system' and self.entity.config: |
|
132 msg = _("Configuration of the system source goes to " |
|
133 "the 'sources' file, not in the database") |
|
134 raise validation_error(self.entity, {('config', 'subject'): msg}) |
|
135 SourceConfigUpdatedOp.get_instance(self._cw).add_data(self.entity) |
125 |
136 |
126 |
137 |
127 class SourceHostConfigUpdatedHook(SourceHook): |
138 class SourceHostConfigUpdatedHook(SourceHook): |
128 __regid__ = 'cw.sources.hostconfigupdate' |
139 __regid__ = 'cw.sources.hostconfigupdate' |
129 __select__ = SourceHook.__select__ & is_instance('CWSourceHostConfig') |
140 __select__ = SourceHook.__select__ & is_instance('CWSourceHostConfig') |