hooks/syncsources.py
changeset 7894 ad0eeb0f7a8d
parent 7879 9aae456abab5
child 8190 2a3c1b787688
equal deleted inserted replaced
7889:6cebeb1f386a 7894:ad0eeb0f7a8d
    32 
    32 
    33 
    33 
    34 # repo sources synchronization #################################################
    34 # repo sources synchronization #################################################
    35 
    35 
    36 class SourceAddedOp(hook.Operation):
    36 class SourceAddedOp(hook.Operation):
       
    37     entity = None # make pylint happy
    37     def postcommit_event(self):
    38     def postcommit_event(self):
    38         self.session.repo.add_source(self.entity)
    39         self.session.repo.add_source(self.entity)
    39 
    40 
    40 class SourceAddedHook(SourceHook):
    41 class SourceAddedHook(SourceHook):
    41     __regid__ = 'cw.sources.added'
    42     __regid__ = 'cw.sources.added'
    52                                   fail_if_unknown=not self._cw.vreg.config.repairing)
    53                                   fail_if_unknown=not self._cw.vreg.config.repairing)
    53         SourceAddedOp(self._cw, entity=self.entity)
    54         SourceAddedOp(self._cw, entity=self.entity)
    54 
    55 
    55 
    56 
    56 class SourceRemovedOp(hook.Operation):
    57 class SourceRemovedOp(hook.Operation):
       
    58     uri = None # make pylint happy
    57     def postcommit_event(self):
    59     def postcommit_event(self):
    58         self.session.repo.remove_source(self.uri)
    60         self.session.repo.remove_source(self.uri)
    59 
    61 
    60 class SourceRemovedHook(SourceHook):
    62 class SourceRemovedHook(SourceHook):
    61     __regid__ = 'cw.sources.removed'
    63     __regid__ = 'cw.sources.removed'
    80         for source, conf in self.__processed:
    82         for source, conf in self.__processed:
    81             source.repo_source.update_config(source, conf)
    83             source.repo_source.update_config(source, conf)
    82 
    84 
    83 
    85 
    84 class SourceRenamedOp(hook.LateOperation):
    86 class SourceRenamedOp(hook.LateOperation):
       
    87     oldname = newname = None # make pylint happy
    85 
    88 
    86     def precommit_event(self):
    89     def precommit_event(self):
    87         source = self.session.repo.sources_by_uri[self.oldname]
    90         source = self.session.repo.sources_by_uri[self.oldname]
    88         if source.copy_based_source:
    91         if source.copy_based_source:
    89             sql = 'UPDATE entities SET asource=%(newname)s WHERE asource=%(oldname)s'
    92             sql = 'UPDATE entities SET asource=%(newname)s WHERE asource=%(oldname)s'
   139 # source mapping synchronization ###############################################
   142 # source mapping synchronization ###############################################
   140 #
   143 #
   141 # Expect cw_for_source/cw_schema are immutable relations (i.e. can't change from
   144 # Expect cw_for_source/cw_schema are immutable relations (i.e. can't change from
   142 # a source or schema to another).
   145 # a source or schema to another).
   143 
   146 
   144 class SourceMappingDeleteHook(SourceHook):
   147 class SourceMappingImmutableHook(SourceHook):
   145     """check cw_for_source and cw_schema are immutable relations
   148     """check cw_for_source and cw_schema are immutable relations
   146 
   149 
   147     XXX empty delete perms would be enough?
   150     XXX empty delete perms would be enough?
   148     """
   151     """
   149     __regid__ = 'cw.sources.delschemaconfig'
   152     __regid__ = 'cw.sources.mapping.immutable'
   150     __select__ = SourceHook.__select__ & hook.match_rtype('cw_for_source', 'cw_schema')
   153     __select__ = SourceHook.__select__ & hook.match_rtype('cw_for_source', 'cw_schema')
   151     events = ('before_add_relation',)
   154     events = ('before_add_relation',)
   152     def __call__(self):
   155     def __call__(self):
   153         if not self._cw.added_in_transaction(self.eidfrom):
   156         if not self._cw.added_in_transaction(self.eidfrom):
   154             msg = self._cw._("can't change this relation")
   157             msg = self._cw._("can't change this relation")