From 75b2108b477427392762d0d38b1b01dd8692324a Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 29 Mar 2017 20:56:22 +0000 Subject: [PATCH] Remove old files --- yaboli/exceptions.py | 41 ------------ yaboli/messages.py | 154 ------------------------------------------- yaboli/sessions.py | 146 ---------------------------------------- 3 files changed, 341 deletions(-) delete mode 100644 yaboli/exceptions.py delete mode 100644 yaboli/messages.py delete mode 100644 yaboli/sessions.py diff --git a/yaboli/exceptions.py b/yaboli/exceptions.py deleted file mode 100644 index f48993d..0000000 --- a/yaboli/exceptions.py +++ /dev/null @@ -1,41 +0,0 @@ -class YaboliException(Exception): - """ - Generic yaboli exception class. - """ - - pass - -class BotManagerException(YaboliException): - """ - Generic BotManager exception class. - """ - - pass - -class CreateBotException(BotManagerException): - """ - This exception will be raised when BotManager could not create a bot. - """ - - pass - -class BotNotFoundException(BotManagerException): - """ - This exception will be raised when BotManager could not find a bot. - """ - - pass - -class BotException(YaboliException): - """ - Generic Bot exception class. - """ - - pass - -class ParseMessageException(BotException): - """ - This exception will be raised when a failure parsing a message occurs. - """ - - pass diff --git a/yaboli/messages.py b/yaboli/messages.py deleted file mode 100644 index 8382a69..0000000 --- a/yaboli/messages.py +++ /dev/null @@ -1,154 +0,0 @@ -import operator - -from . import message - -class Messages(): - """ - Message storage class which preserves thread hierarchy. - """ - - def __init__(self, message_limit=500): - """ - message_limit - maximum amount of messages that will be stored at a time - None - no limit - """ - - self.message_limit = message_limit - - self._by_id = {} - self._by_parent = {} - - def _sort(self, msgs): - """ - _sort(messages) -> None - - Sorts a list of messages by their id, in place. - """ - - msgs.sort(key=operator.attrgetter("id")) - - def add_from_data(self, data): - """ - add_from_data(data) -> None - - Create a message from "raw" data and add it. - """ - - mes = message.Message.from_data(data) - - self.add(mes) - - def add(self, mes): - """ - add(message) -> None - - Add a message to the structure. - """ - - self.remove(mes.id) - - self._by_id[mes.id] = mes - - if mes.parent: - if not mes.parent in self._by_parent: - self._by_parent[mes.parent] = [] - self._by_parent[mes.parent].append(mes) - - if self.message_limit and len(self._by_id) > self.message_limit: - self.remove(self.get_oldest().id) - - def remove(self, mid): - """ - remove(message_id) -> None - - Remove a message from the structure. - """ - - mes = self.get(mid) - if mes: - if mes.id in self._by_id: - self._by_id.pop(mes.id) - - parent = self.get_parent(mes.id) - if parent and mes in self.get_children(parent.id): - self._by_parent[mes.parent].remove(mes) - - def remove_all(self): - """ - remove_all() -> None - - Removes all messages. - """ - - self._by_id = {} - self._by_parent = {} - - def get(self, mid): - """ - get(message_id) -> Message - - Returns the message with the given id, if found. - """ - - if mid in self._by_id: - return self._by_id[mid] - - def get_oldest(self): - """ - get_oldest() -> Message - - Returns the oldest message, if found. - """ - - oldest = None - for mid in self._by_id: - if oldest is None or mid < oldest: - oldest = mid - return self.get(oldest) - - def get_youngest(self): - """ - get_youngest() -> Message - - Returns the youngest message, if found. - """ - - youngest = None - for mid in self._by_id: - if youngest is None or mid > youngest: - youngest = mid - return self.get(youngest) - - def get_parent(self, mid): - """ - get_parent(message_id) -> str - - Returns the message's parent, if found. - """ - - mes = self.get(mid) - if mes: - return self.get(mes.parent) - - def get_children(self, mid): - """ - get_children(message_id) -> list - - Returns a sorted list of children of the given message, if found. - """ - - if mid in self._by_parent: - children = self._by_parent[mid][:] - self._sort(children) - return children - - def get_top_level(self): - """ - get_top_level() -> list - - Returns a sorted list of top-level messages. - """ - - msgs = [self.get(mid) for mid in self._by_id if not self.get(mid).parent] - self._sort(msgs) - return msgs diff --git a/yaboli/sessions.py b/yaboli/sessions.py deleted file mode 100644 index b00cf75..0000000 --- a/yaboli/sessions.py +++ /dev/null @@ -1,146 +0,0 @@ -from . import session - -class Sessions(): - """ - Keeps track of sessions. - """ - - def __init__(self): - """ - TODO - """ - self._sessions = {} - - def add_from_data(self, data): - """ - add_raw(data) -> None - - Create a session from "raw" data and add it. - """ - - ses = session.Session.from_data(data) - - self._sessions[ses.session_id] = ses - - def add(self, ses): - """ - add(session) -> None - - Add a session. - """ - - self._sessions[ses.session_id] = ses - - def get(self, sid): - """ - get(session_id) -> Session - - Returns the session with that id. - """ - - if sid in self._sessions: - return self._sessions[sid] - - def remove(self, sid): - """ - remove(session) -> None - - Remove a session. - """ - - if sid in self._sessions: - self._sessions.pop(sid) - - def remove_on_network_partition(self, server_id, server_era): - """ - remove_on_network_partition(server_id, server_era) -> None - - Removes all sessions matching the server_id/server_era combo. - http://api.euphoria.io/#network-event - """ - - sesnew = {} - for sid in self._sessions: - ses = self.get(sid) - if not (ses.server_id == server_id and ses.server_era == server_era): - sesnew[sid] = ses - self._sessions = sesnew - - def remove_all(self): - """ - remove_all() -> None - - Removes all sessions. - """ - - self._sessions = {} - - def get_all(self): - """ - get_all() -> list - - Returns the full list of sessions. - """ - - return [ses for sid, ses in self._sessions.items()] - - def get_people(self): - """ - get_people() -> list - - Returns a list of all non-bot and non-lurker sessions. - """ - - # not a list comprehension because that would span several lines too - people = [] - for sid in self._sessions: - ses = self.get(sid) - if ses.session_type() in ["agent", "account"] and ses.name: - people.append(ses) - return people - - def _get_by_type(self, tp): - """ - _get_by_type(session_type) -> list - - Returns a list of all non-lurker sessions with that type. - """ - - return [ses for sid, ses in self._sessions.items() - if ses.session_type() == tp and ses.name] - - def get_accounts(self): - """ - get_accounts() -> list - - Returns a list of all logged-in sessions. - """ - - return self._get_by_type("account") - - def get_agents(self): - """ - get_agents() -> list - - Returns a list of all sessions who are not signed into an account and not bots or lurkers. - """ - - return self._get_by_type("agent") - - def get_bots(self): - """ - get_bots() -> list - - Returns a list of all bot sessions. - """ - - return self._get_by_type("bot") - - def get_lurkers(self): - """ - get_lurkers() -> list - - Returns a list of all lurker sessions. - """ - - return [ses for sid, ses in self._sessions.items() if not ses.name]