Merge branch 'master' into feature/write-thread

This commit is contained in:
jesopo 2019-06-07 15:07:31 +01:00
commit f822345976
4 changed files with 24 additions and 20 deletions

View file

@ -584,6 +584,8 @@ class Module(ModuleManager.BaseModule):
else: else:
action_desc = "%s %s" % ( action_desc = "%s %s" % (
utils.irc.color("closed", COLOR_NEGATIVE), number) utils.irc.color("closed", COLOR_NEGATIVE), number)
elif action == "ready_for_review":
action_desc = "marked %s ready for review" % number
elif action == "synchronize": elif action == "synchronize":
action_desc = "committed to %s" % number action_desc = "committed to %s" % number

View file

@ -30,11 +30,11 @@ class Bot(object):
self._event_queue = queue.Queue() self._event_queue = queue.Queue()
self._read_poll = select.epoll() self._read_poll = select.poll()
self._write_poll = select.epoll() self._write_poll = select.poll()
self._rtrigger_server, self._rtrigger_client = socket.socketpair() self._rtrigger_server, self._rtrigger_client = socket.socketpair()
self._read_poll.register(self._rtrigger_server.fileno(), select.EPOLLIN) self._read_poll.register(self._rtrigger_server.fileno(), select.POLLIN)
self._rtrigger_lock = threading.Lock() self._rtrigger_lock = threading.Lock()
self._rtriggered = False self._rtriggered = False
@ -145,7 +145,7 @@ class Bot(object):
[str(server), str(e)]) [str(server), str(e)])
return False return False
self.servers[server.fileno()] = server self.servers[server.fileno()] = server
self._read_poll.register(server.fileno(), select.EPOLLIN) self._read_poll.register(server.fileno(), select.POLLIN)
return True return True
def next_send(self) -> typing.Optional[float]: def next_send(self) -> typing.Optional[float]:
@ -182,7 +182,8 @@ class Bot(object):
timeouts.append(self.next_ping()) timeouts.append(self.next_ping())
timeouts.append(self.next_read_timeout()) timeouts.append(self.next_read_timeout())
timeouts.append(self.cache.next_expiration()) timeouts.append(self.cache.next_expiration())
return min([timeout for timeout in timeouts if not timeout == None]) min_secs = min([timeout for timeout in timeouts if not timeout == None])
return min_secs*1000 # return milliseconds
def disconnect(self, server: IRCServer.Server): def disconnect(self, server: IRCServer.Server):
del self.servers[server.fileno()] del self.servers[server.fileno()]
@ -249,7 +250,7 @@ class Bot(object):
writeable = False writeable = False
for fd, server in self.servers.items(): for fd, server in self.servers.items():
if server.socket.waiting_immediate_send(): if server.socket.waiting_immediate_send():
self._write_poll.register(fd, select.EPOLLOUT) self._write_poll.register(fd, select.POLLOUT)
writeable = True writeable = True
if not writeable: if not writeable:
@ -259,7 +260,7 @@ class Bot(object):
events = self._write_poll.poll() events = self._write_poll.poll()
for fd, event in events: for fd, event in events:
if event & select.EPOLLOUT: if event & select.POLLOUT:
self._write_poll.unregister(fd) self._write_poll.unregister(fd)
if fd in self.servers: if fd in self.servers:
server = self.servers[fd] server = self.servers[fd]
@ -296,7 +297,7 @@ class Bot(object):
continue continue
server = self.servers[fd] server = self.servers[fd]
if event & select.EPOLLIN: if event & select.POLLIN:
lines = server.read() lines = server.read()
if lines == None: if lines == None:
server.disconnect() server.disconnect()
@ -304,8 +305,8 @@ class Bot(object):
self.trigger(self._post_read_factory(server, lines), self.trigger(self._post_read_factory(server, lines),
False) False)
elif event & select.EPOLLHUP: elif event & select.POLLHUP:
self.log.warn("Recieved EPOLLHUP for %s", [str(server)]) self.log.warn("Recieved POLLHUP for %s", [str(server)])
server.disconnect() server.disconnect()
def _check(self): def _check(self):

View file

@ -1,6 +1,8 @@
import re, typing import collections, re, typing
from src import IRCBot, IRCServer, utils from src import IRCBot, IRCServer, utils
MAX_LINES = 64
class BufferLine(object): class BufferLine(object):
def __init__(self, sender: str, message: str, action: bool, tags: dict, def __init__(self, sender: str, message: str, action: bool, tags: dict,
from_self: bool, method: str): from_self: bool, method: str):
@ -15,17 +17,15 @@ class Buffer(object):
def __init__(self, bot: "IRCBot.Bot", server: "IRCServer.Server"): def __init__(self, bot: "IRCBot.Bot", server: "IRCServer.Server"):
self.bot = bot self.bot = bot
self.server = server self.server = server
self.lines = [] # type: typing.List[BufferLine] self._lines = collections.deque(maxlen=MAX_LINES
self.max_lines = 64 ) # type: typing.Deque[BufferLine]
self._skip_next = False self._skip_next = False
def _add_message(self, sender: str, message: str, action: bool, tags: dict, def _add_message(self, sender: str, message: str, action: bool, tags: dict,
from_self: bool, method: str): from_self: bool, method: str):
if not self._skip_next: if not self._skip_next:
line = BufferLine(sender, message, action, tags, from_self, method) line = BufferLine(sender, message, action, tags, from_self, method)
self.lines.insert(0, line) self._lines.appendleft(line)
if len(self.lines) > self.max_lines:
self.lines.pop()
self._skip_next = False self._skip_next = False
def add_message(self, sender: str, message: str, action: bool, tags: dict, def add_message(self, sender: str, message: str, action: bool, tags: dict,
from_self: bool=False): from_self: bool=False):
@ -36,7 +36,7 @@ class Buffer(object):
def get(self, index: int=0, **kwargs) -> typing.Optional[BufferLine]: def get(self, index: int=0, **kwargs) -> typing.Optional[BufferLine]:
from_self = kwargs.get("from_self", True) from_self = kwargs.get("from_self", True)
for line in self.lines: for line in self._lines:
if line.from_self and not from_self: if line.from_self and not from_self:
continue continue
return line return line
@ -47,7 +47,7 @@ class Buffer(object):
for_user = kwargs.get("for_user", "") for_user = kwargs.get("for_user", "")
for_user = self.server.irc_lower(for_user) if for_user else None for_user = self.server.irc_lower(for_user) if for_user else None
not_pattern = kwargs.get("not_pattern", None) not_pattern = kwargs.get("not_pattern", None)
for line in self.lines: for line in self._lines:
if line.from_self and not from_self: if line.from_self and not from_self:
continue continue
elif re.search(pattern, line.message): elif re.search(pattern, line.message):
@ -61,7 +61,7 @@ class Buffer(object):
def find_from(self, nickname: str) -> typing.Optional[BufferLine]: def find_from(self, nickname: str) -> typing.Optional[BufferLine]:
nickname_lower = self.server.irc_lower(nickname) nickname_lower = self.server.irc_lower(nickname)
for line in self.lines: for line in self._lines:
if (not line.from_self if (not line.from_self
and self.server.irc_lower(line.sender) == nickname_lower): and self.server.irc_lower(line.sender) == nickname_lower):
return line return line

View file

@ -61,5 +61,6 @@ class Log(object):
self._log(message, params, logging.ERROR, kwargs) self._log(message, params, logging.ERROR, kwargs)
def critical(self, message: str, params: typing.List=None, **kwargs): def critical(self, message: str, params: typing.List=None, **kwargs):
self._log(message, params, logging.CRITICAL, kwargs) self._log(message, params, logging.CRITICAL, kwargs)
def _log(self, message: str, params: typing.List, level: int, kwargs: dict): def _log(self, message: str, params: typing.Optional[typing.List],
level: int, kwargs: dict):
self.logger.log(level, message, *(params or []), **kwargs) self.logger.log(level, message, *(params or []), **kwargs)