'Cleans up all SearchCommunity and MetadataCommunity stuff in dispersy database.'

def _update_dispersy(self):

    db_path = os.path.join(self.state_dir, u'sqlite', u'dispersy.db')
    if (not os.path.isfile(db_path)):
        return
    communities_to_delete = (u'SearchCommunity', u'MetadataCommunity')
    connection = Connection(db_path)
    cursor = connection.cursor()
    data_updated = False
    for community in communities_to_delete:
        try:
            result = list(cursor.execute(u'SELECT    id    FROM    community    WHERE    classification    ==    ?', (community,)))
            for (community_id,) in result:
                self._logger.info(u'deleting    all    data    for    community    %s...', community_id)
                cursor.execute(u'DELETE    FROM    community    WHERE    id    ==    ?', (community_id,))
                cursor.execute(u'DELETE    FROM    meta_message    WHERE    community    ==    ?', (community_id,))
                cursor.execute(u'DELETE    FROM    sync    WHERE    community    ==    ?', (community_id,))
                data_updated = True
        except StopIteration:
            continue
    if data_updated:
        connection.commit()
    cursor.close()
    connection.close()
