mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Added docstrings, fixed some weird indentation.
This commit is contained in:
parent
c1a2f1b454
commit
6261036911
@ -49,8 +49,7 @@ _deadDrivers = []
|
|||||||
_newDrivers = []
|
_newDrivers = []
|
||||||
|
|
||||||
class IrcDriver(object):
|
class IrcDriver(object):
|
||||||
"""Base class for drivers.
|
"""Base class for drivers."""
|
||||||
"""
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
_newDrivers.append((self.name(), self))
|
_newDrivers.append((self.name(), self))
|
||||||
if not hasattr(self, 'irc'):
|
if not hasattr(self, 'irc'):
|
||||||
@ -115,15 +114,19 @@ class Interactive(IrcDriver):
|
|||||||
self.irc.feedMsg(msg)
|
self.irc.feedMsg(msg)
|
||||||
|
|
||||||
def empty():
|
def empty():
|
||||||
|
"""Returns whether or not the driver loop is empty."""
|
||||||
return (len(_drivers) + len(_newDrivers)) == 0
|
return (len(_drivers) + len(_newDrivers)) == 0
|
||||||
|
|
||||||
def add(name, driver):
|
def add(name, driver):
|
||||||
|
"""Adds a given driver the loop with the given name."""
|
||||||
_newDrivers.append((name, driver))
|
_newDrivers.append((name, driver))
|
||||||
|
|
||||||
def remove(name):
|
def remove(name):
|
||||||
|
"""Removes the driver with the given name from the loop."""
|
||||||
_deadDrivers.append(name)
|
_deadDrivers.append(name)
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
"""Runs the whole driver loop."""
|
||||||
for (name, driver) in _drivers.iteritems():
|
for (name, driver) in _drivers.iteritems():
|
||||||
try:
|
try:
|
||||||
if name not in _deadDrivers:
|
if name not in _deadDrivers:
|
||||||
@ -137,13 +140,14 @@ def run():
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
while _newDrivers:
|
while _newDrivers:
|
||||||
(name, driver) = _newDrivers.pop()
|
(name, driver) = _newDrivers.pop()
|
||||||
if name in _drivers:
|
if name in _drivers:
|
||||||
_drivers[name].die()
|
_drivers[name].die()
|
||||||
del _drivers[name]
|
del _drivers[name]
|
||||||
_drivers[name] = driver
|
_drivers[name] = driver
|
||||||
|
|
||||||
def newDriver(server, irc, moduleName=conf.driverModule):
|
def newDriver(server, irc, moduleName=conf.driverModule):
|
||||||
|
"""Returns a new driver for the given server using conf.driverModule."""
|
||||||
driver = __import__(moduleName).Driver(server, irc)
|
driver = __import__(moduleName).Driver(server, irc)
|
||||||
irc.driver = driver
|
irc.driver = driver
|
||||||
return driver
|
return driver
|
||||||
|
Loading…
Reference in New Issue
Block a user