def _post_process_tags(self):
        """Process possible after-effects of tags. This may include removing
        spreads, roles and such.

        Currently only spreads are supported."""
        # Do nothing if the config doesn't have TAG_REWRITE or it's empty.
        # In the latter case you get very serious side-effects that will wipe
        # all spreads on all entities due to entity.list_all_with_spread()'s
        # way of handling an empty argument.
        if not hasattr(abcconf, "TAG_REWRITE") or not abcconf.TAG_REWRITE:
            return
        # Access Entity objects directly.
        from Cerebrum.Entity import EntitySpread
        es = EntitySpread(self.db)
        for row in es.list_all_with_spread(
                [int(s) for s in abcconf.TAG_REWRITE.values()]):
            if int(row['entity_id']) in self._spreads:
                # Entity found, check spreads in database
                if (not int(row['spread']) in
                        self._spreads[int(row['entity_id'])]):
                    es.clear()
                    es.find(int(row['entity_id']))
                    es.delete_spread(int(row['spread']))
                    self.logger.info("Entity: '%d', removed spread '%s'" %
                                     (es.entity_id, int(row['spread'])))
            else:
                # Entity missing from file, remove all spreads
                es.clear()
                es.find(int(row['entity_id']))
                es.delete_spread(int(row['spread']))
                self.logger.info("Entity: '%d', removed spread '%s'" %
                                 (es.entity_id, int(row['spread'])))
Example #2
0
    def _post_process_tags(self):
        """Process possible after-effects of tags. This may include removing
        spreads, roles and such.

        Currently only spreads are supported."""
        # Do nothing if the config doesn't have TAG_REWRITE or it's empty.
        # In the latter case you get very serious side-effects that will wipe all
        # spreads on all entities due to entity.list_all_with_spread()'s way of
        # handling an empty argument.
        if not hasattr(abcconf, "TAG_REWRITE") or not abcconf.TAG_REWRITE:
            return
        # Access Entity objects directly.
        from Cerebrum.Entity import EntitySpread

        es = EntitySpread(self.db)
        for row in es.list_all_with_spread([int(s) for s in abcconf.TAG_REWRITE.values()]):
            if self._spreads.has_key(int(row["entity_id"])):
                # Entity found, check spreads in database
                if not int(row["spread"]) in self._spreads[int(row["entity_id"])]:
                    es.clear()
                    es.find(int(row["entity_id"]))
                    es.delete_spread(int(row["spread"]))
                    self.logger.info("Entity: '%d', removed spread '%s'" % (es.entity_id, int(row["spread"])))
            else:
                # Entity missing from file, remove all spreads
                es.clear()
                es.find(int(row["entity_id"]))
                es.delete_spread(int(row["spread"]))
                self.logger.info("Entity: '%d', removed spread '%s'" % (es.entity_id, int(row["spread"])))