mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 08:34:00 +02:00
Topic retrieval works. Test code
This commit is contained in:
parent
c5df06fc82
commit
4ab81c8740
1 changed files with 33 additions and 16 deletions
|
@ -18,6 +18,8 @@ from nfc_smartcard import NFCDevice, NFCError
|
||||||
from brmdoor_authenticator import UidAuthenticator, YubikeyHMACAuthenthicator, DesfireEd25519Authenthicator
|
from brmdoor_authenticator import UidAuthenticator, YubikeyHMACAuthenthicator, DesfireEd25519Authenthicator
|
||||||
import unlocker
|
import unlocker
|
||||||
|
|
||||||
|
channelPrefixMap = {}
|
||||||
|
|
||||||
class BrmdoorConfigError(ConfigParser.Error):
|
class BrmdoorConfigError(ConfigParser.Error):
|
||||||
"""
|
"""
|
||||||
Signifies that config has missing or bad values.
|
Signifies that config has missing or bad values.
|
||||||
|
@ -134,6 +136,8 @@ class NFCScanner(object):
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Exception in main unlock thread")
|
logging.exception("Exception in main unlock thread")
|
||||||
|
logging.info("Request topic")
|
||||||
|
self.ircThread.getTopic(self.ircThread.channels[0])
|
||||||
|
|
||||||
def sendIrcMessage(self, msg):
|
def sendIrcMessage(self, msg):
|
||||||
"""
|
"""
|
||||||
|
@ -240,9 +244,9 @@ class IrcThread(threading.Thread):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getTopic(self, channel):
|
def getTopic(self, channel):
|
||||||
""" TODO: this doesn't work, the implementation always returns None"""
|
""" Request topic. You need to wait in currenttopic callback for result """
|
||||||
with self.threadLock:
|
with self.threadLock:
|
||||||
return self.connection.topic(channel)
|
self.connection.topic(channel)
|
||||||
|
|
||||||
def setTopic(self, channel, newTopic):
|
def setTopic(self, channel, newTopic):
|
||||||
with self.threadLock:
|
with self.threadLock:
|
||||||
|
@ -266,7 +270,17 @@ class IrcThread(threading.Thread):
|
||||||
#connection.privmsg(self.channels[0], "brmbot-libfc starting")
|
#connection.privmsg(self.channels[0], "brmbot-libfc starting")
|
||||||
|
|
||||||
def onTopic(self, connection, event):
|
def onTopic(self, connection, event):
|
||||||
logging.debug("topic event - source %s, target: %s, type: %s", event.source, event.target, event.type)
|
global channelPrefixMap
|
||||||
|
channel = event.arguments[0]
|
||||||
|
topic = event.arguments[1]
|
||||||
|
logging.info("Current topic: channel %s, topic %s", channel, topic)
|
||||||
|
logging.info("Topic event - source %s, target: %s, type: %s", event.source, event.target, event.type)
|
||||||
|
|
||||||
|
def onNoTopic(self, connection, event):
|
||||||
|
channel = event.arguments[0]
|
||||||
|
topic = event.arguments[1]
|
||||||
|
logging.info("No topic: channel %s, topic %s", channel, topic)
|
||||||
|
logging.info("No topic event - source %s, target: %s, type: %s", event.source, event.target, event.type)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
logging.debug("Starting IRC thread")
|
logging.debug("Starting IRC thread")
|
||||||
|
@ -278,6 +292,9 @@ class IrcThread(threading.Thread):
|
||||||
self.connection.add_global_handler("welcome", partial(IrcThread.onConnect, self))
|
self.connection.add_global_handler("welcome", partial(IrcThread.onConnect, self))
|
||||||
self.connection.add_global_handler("disconnect", partial(IrcThread.onDisconnect, self))
|
self.connection.add_global_handler("disconnect", partial(IrcThread.onDisconnect, self))
|
||||||
self.connection.add_global_handler("join", partial(IrcThread.onJoin, self))
|
self.connection.add_global_handler("join", partial(IrcThread.onJoin, self))
|
||||||
|
self.reactor.server().add_global_handler("notopic", partial(IrcThread.onNoTopic, self))
|
||||||
|
self.reactor.server().add_global_handler("currenttopic", partial(IrcThread.onTopic, self))
|
||||||
|
|
||||||
# Topic handler requires sadly completely different API to retrieve topic
|
# Topic handler requires sadly completely different API to retrieve topic
|
||||||
# see https://github.com/jaraco/irc/issues/132
|
# see https://github.com/jaraco/irc/issues/132
|
||||||
|
|
||||||
|
@ -329,6 +346,7 @@ class OpenSwitchThread(threading.Thread):
|
||||||
strStatus = "CLOSED |"
|
strStatus = "CLOSED |"
|
||||||
|
|
||||||
if self.ircThread.connected:
|
if self.ircThread.connected:
|
||||||
|
with self.ircThread.threadLock:
|
||||||
for channel in self.ircThread.channels:
|
for channel in self.ircThread.channels:
|
||||||
#TODO: getTopic always returns None, the problem is in implementenation
|
#TODO: getTopic always returns None, the problem is in implementenation
|
||||||
topic = self.ircThread.getTopic(channel)
|
topic = self.ircThread.getTopic(channel)
|
||||||
|
@ -373,11 +391,10 @@ if __name__ == "__main__":
|
||||||
ircThread = IrcThread(config, ircMsgQueue)
|
ircThread = IrcThread(config, ircMsgQueue)
|
||||||
ircThread.setDaemon(True)
|
ircThread.setDaemon(True)
|
||||||
ircThread.start()
|
ircThread.start()
|
||||||
# Disable for now, topic is not working properly
|
if config.useOpenSwitch:
|
||||||
# if config.useOpenSwitch:
|
openSwitchThread = OpenSwitchThread(config, ircThread)
|
||||||
# openSwitchThread = OpenSwitchThread(config, ircThread)
|
openSwitchThread.setDaemon(True)
|
||||||
# openSwitchThread.setDaemon(True)
|
openSwitchThread.start()
|
||||||
# openSwitchThread.start()
|
|
||||||
|
|
||||||
nfcScanner = NFCScanner(config, ircMsgQueue, ircThread)
|
nfcScanner = NFCScanner(config, ircMsgQueue, ircThread)
|
||||||
nfcScanner.run()
|
nfcScanner.run()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue