Esempio n. 1
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"])))
def get_enabled_accounts(db):
    """ Get accounts with spreads.

    Accounts with spreads will not be considered `Account.is_deleted()` or
    `Account.is_reserved()`.
    """
    es = EntitySpread(db)
    co = Factory.get('Constants')(db)
    return set(e_id for e_id, s_code in
               es.list_all_with_spread(entity_types=co.entity_account))
 def __init__(self, db, entity_types):
     es = EntitySpread(db)
     data = defaultdict(set)
     for e_id, s_code in es.list_all_with_spread(entity_types=entity_types):
         data[e_id].add(s_code)
     self.data = dict(data)