[Otfbot-svn] r116 - in trunk: . helpers

cato- at BerliOS cato-
Sa Jun 23 18:41:13 CEST 2007


Author: cato-
Date: 2007-06-23 18:41:08 +0200 (Sat, 23 Jun 2007)
New Revision: 116

Added:
   trunk/helpers/generate_doc.sh
   trunk/scheduler_ng.py
Modified:
   trunk/helpers/TCPclient.py
   trunk/otfbot.py
Log:
* new scheduler


Modified: trunk/helpers/TCPclient.py
===================================================================
--- trunk/helpers/TCPclient.py	2007-06-23 16:25:22 UTC (rev 115)
+++ trunk/helpers/TCPclient.py	2007-06-23 16:41:08 UTC (rev 116)
@@ -1,3 +1,4 @@
+#!/usr/bin/python
 from twisted.internet import protocol, error, reactor
 from threading import Thread
 from twisted.protocols import basic

Added: trunk/helpers/generate_doc.sh
===================================================================
--- trunk/helpers/generate_doc.sh	2007-06-23 16:25:22 UTC (rev 115)
+++ trunk/helpers/generate_doc.sh	2007-06-23 16:41:08 UTC (rev 116)
@@ -0,0 +1,19 @@
+#!/bin/bash
+# You need:
+#  * pydoctor: - get latest svn from http://codespeak.net/~mwh/pydoctor/
+#              - sudo python setup.py install
+#  * Nevow: - latest stable from http://www.divmod.org/trac/wiki/DivmodNevow#Download
+#           - unpack, sudo python setup.py install
+# Just upload the whole directory "apidocs" (which this script creates) to /home/groups/otfbot/htdocs/pages
+
+curdir=`pwd`
+dir=`dirname $0`
+cd $dir/..
+touch __init__.py
+touch modules/__init__.py
+pydoctor 	--add-package=. \
+		--project-name="OtfBot" \
+		--project-url="http://otfbot.berlios.de/" \
+		--make-html
+rm __init__.py modules/__init__.py
+cd $curdir


Property changes on: trunk/helpers/generate_doc.sh
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/otfbot.py
===================================================================
--- trunk/otfbot.py	2007-06-23 16:25:22 UTC (rev 115)
+++ trunk/otfbot.py	2007-06-23 16:41:08 UTC (rev 116)
@@ -25,7 +25,7 @@
 
 from twisted.internet import reactor, protocol, error, ssl
 import os, random, string, re, sys, traceback, atexit
-import functions, config, scheduler
+import functions, config, scheduler, scheduler_ng
 
 
 # some constants, can be retrieved from serveranswer while connecting.
@@ -183,7 +183,7 @@
     schedulethread.addScheduleJob(time, function)
     
 class Bot(irc.IRCClient):
-    """A Chat Bot"""
+    """The Protocol of our IRC-Bot"""
     def __init__(self):
         #list of mods, which the bot should use
         #you may need to configure them first
@@ -202,8 +202,14 @@
         self.logger = logging.getLogger("core")
         self.logger.info("Starting new Botinstance")
         self.startMods()
+        self.scheduler = scheduler_ng.Scheduler(self.getReactor())
+        self.scheduler.addJob(10,self.test)
+    
+    def test(self):
+        self.logger.debug("hallo")
 
     def _apirunner(self,apifunction,args={}):
+        """Pass all calls to modules callbacks through this method, they are checked whether they should be execeted or not"""
         for mod in self.mods:
             if (args.has_key("channel") and args["channel"] in self.channels and self.getBoolConfig("enabled","True",mod.name,self.network,args["channel"])) or not args.has_key("channel") or args["channel"] not in self.channels:
                 try:
@@ -224,6 +230,7 @@
             #except AttributeError:
             #    pass
         self._apirunner("start")
+    # configstuff, should maybe be moved to a config-instance at self.config
     def setConfig(self, option, value, module=None, network=None, channel=None):
         return setConfig(option, value, module, network, channel)
     def hasConfig(self, option, module=None):
@@ -242,10 +249,13 @@
         return loadConfig(configfile)
     def writeConfig(self):
         return writeConfig()
+    # Schedular
+    def addScheduleJob(self, time, function):
+        self.log.warn("Call to deprecated method addScheduleJob")
+        return addScheduleJob(time, function)
+    
     def getUsers(self):
         return self.users
-    def addScheduleJob(self, time, function):
-        return addScheduleJob(time, function)
     def getReactor(self):
         return reactor
     def getFactory(self):

Added: trunk/scheduler_ng.py
===================================================================
--- trunk/scheduler_ng.py	2007-06-23 16:25:22 UTC (rev 115)
+++ trunk/scheduler_ng.py	2007-06-23 16:41:08 UTC (rev 116)
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+#
+# This file is part of OtfBot.
+#
+# OtfBot is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# OtfBot is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with OtfBot; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+# 
+# (c) 2007 by Robert Weidlich
+
+class Scheduler:
+    """Wrapper class for the scheduling functions of twisted.internet.reactor.ReactorTime"""
+    def __init__(self,reactor):
+        self.reactor=reactor
+    def addJob(self,time,function,*args,**kwargs):
+        """executes the given function after time seconds with arguments (*args) and keyword arguments (**kwargs)"""
+        self.reactor.callLater(time,function,*args,**kwargs)
+
+    def addPeriodicJob(self,delay,function,kwargs={}):
+        """executes the given function every delay seconds with keyword arguments (**kwargs)"""
+        def func(delay,function,**kwargs):
+            args=(delay,function)
+            if not function(**kwargs):
+                self.reactor.callLater(delay,func,*args,**kwargs)
+        args=(delay,function)
+        self.reactor.callLater(delay,func,*args,**kwargs)
\ No newline at end of file




Mehr Informationen über die Mailingliste Otfbot-dev