[Otfbot-dev] [Git] OTFBot branch, master, updated. 716fb5133cfb6ee15d006c99cdbdbedc14e212c6

git version control gitrepo at otfbot.org
Mo Nov 1 13:43:55 CET 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OTFBot".

The branch, master has been updated
       via  716fb5133cfb6ee15d006c99cdbdbedc14e212c6 (commit)
      from  e5235b9f614a96388a1807c71888945a26f0b6f7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 716fb5133cfb6ee15d006c99cdbdbedc14e212c6
Author: allo <allo at laxu.de>
Date:   Mon Nov 1 13:43:32 2010 +0100

    threaded logging in one big thread

diff --git a/otfbot/plugins/ircClient/log.py b/otfbot/plugins/ircClient/log.py
index 7f629ba..7cc6b34 100644
--- a/otfbot/plugins/ircClient/log.py
+++ b/otfbot/plugins/ircClient/log.py
@@ -29,6 +29,7 @@ from otfbot.lib.pluginSupport.decorators import callback
 from otfbot.lib.color import filtercolors
 
 import time
+import copy
 import string
 import locale
 import os
@@ -61,6 +62,10 @@ class Plugin(chatMod.chatMod):
         #    self.setNetwork()
         #    self.joined(c)
         self.setNetwork()
+        reactor.callInThread(self.logThread)
+        self.logs=[]
+        self.privateLogs=[]
+        self.stopThread=False
 
     def timemap(self):
         return {'y': self.ts("%Y"), 'm': self.ts("%m"), 'd': self.ts("%d")}
@@ -85,7 +90,7 @@ class Plugin(chatMod.chatMod):
             #TODO: this was already commented out. why don't we do this here?
             #self.log(channel, "--- Day changed "+self.ts("%a %b %d %Y"))
 
-    def log(self, channel, string, timestamp=True):
+    def logThread(self):
         def real_log(self, channel, string, timestamp):
             if self.day != self.ts("%d"):
                 self.dayChange()
@@ -95,9 +100,6 @@ class Plugin(chatMod.chatMod):
                     logmsg = self.ts() + " " + logmsg
                 self.files[channel].write(logmsg.encode("UTF-8"))
                 self.files[channel].flush()
-        reactor.callInThread(real_log, self, channel, string, timestamp)
-
-    def logPrivate(self, user, mystring):
         def real_logPrivate(self, user, mystring):
             if self.doLogPrivate:
                 mystring = filtercolors(mystring)
@@ -109,7 +111,22 @@ class Plugin(chatMod.chatMod):
                 file = open(filename, "a")
                 file.write(self.ts() + " " + mystring.encode("UTF-8") + "\n")
                 file.close()
-        reactor.callInThread(real_logPrivate, self, user, mystring)
+        while not self.stopThread:
+            time.sleep(1)
+            logs=copy.copy(self.logs)
+            self.logs=[]
+            privateLogs=copy.copy(self.privateLogs)
+            self.privateLogs=[]
+            for call in logs:
+                real_log(self, call[0], call[1], call[2])
+            for call in privateLogs:
+                real_logPrivate(self, call[0], call[1])
+
+    def log(self, channel, string, timestamp=True):
+        self.logs.append((channel, string, timestamp))
+
+    def logPrivate(self, user, mystring):
+        self.privateLogs.append((user, mystring))
 
     def openLog(self, channel):
         self.channels[string.lower(channel)] = 1
@@ -215,11 +232,16 @@ class Plugin(chatMod.chatMod):
         for channel in self.channels:
             self.log(channel, "--- Log closed " + self.ts("%a %b %d %H:%M:%S %Y"), False)
             self.files[channel].close()
+        self.stopThread=True
 
     @callback
     def connectionMade(self):
         self.setNetwork()
 
+    @callback
+    def connectionLost(self, reason):
+        self.stop()
+
     def setNetwork(self):
         if len(self.bot.network.split(".")) < 3:
             net = self.bot.network
-----------------------------------------------------------------------

Summary of changes:
 otfbot/plugins/ircClient/log.py |   32 +++++++++++++++++++++++++++-----
 1 files changed, 27 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
OTFBot



Mehr Informationen über die Mailingliste Otfbot-dev