[pybot-commits] CVS: pybot/pybot main.py,1.3,1.4 runner.py,1.1,1.2 server.py,1.2,1.3 core.py,1.2,NON
Brought to you by:
niemeyer
|
From: Gustavo N. <nie...@us...> - 2003-05-09 20:18:39
|
Update of /cvsroot/pybot/pybot/pybot
In directory sc8-pr-cvs1:/tmp/cvs-serv16526/pybot
Modified Files:
main.py runner.py server.py
Removed Files:
core.py
Log Message:
- modules/userdata.py,modules/permission.py: A much better userdata
registry and permission system was developed.
- misc.py: Increased maximum line size to 400 characters.
- server.py,runner.py,modules/permission.py: Implemented a
pybot console, allowing one to talk to pybot locally.
- scripts/*: Removed setup scripts. They're not needed anymore
now that we have a console.
- core.py: Removed (why was it still here?).
- modules/options.py: Get filename from configuration file.
Index: main.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/main.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** main.py 4 Dec 2001 00:57:38 -0000 1.3
--- main.py 9 May 2003 20:18:36 -0000 1.4
***************
*** 33,40 ****
self.reboot = 0
self.quit = 0
! # Aaron told SIGQUIT is not available in Windows. We must figure
! # out which platforms it is available and what's the most clean
! # way to use it.
! # signal.signal(signal.SIGQUIT, self.signalhandler)
signal.signal(signal.SIGTERM, self.signalhandler)
--- 33,37 ----
self.reboot = 0
self.quit = 0
! signal.signal(signal.SIGQUIT, self.signalhandler)
signal.signal(signal.SIGTERM, self.signalhandler)
Index: runner.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/runner.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** runner.py 4 Dec 2001 00:57:38 -0000 1.1
--- runner.py 9 May 2003 20:18:36 -0000 1.2
***************
*** 19,24 ****
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! import sys
! import os
# Add upper directory to search path in case we are in development tree.
--- 19,24 ----
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! import sys, os
! import getopt
# Add upper directory to search path in case we are in development tree.
***************
*** 28,63 ****
def print_cmd(cmd):
! print "Command(%s): %s"%(cmd.cmd, cmd.line)
!
def print_msg(msg):
! print "Message(%s/%s): %s"%(msg.target, msg.user.nick, msg.line)
!
def print_not(msg):
! print "Notice(%s/%s): %s"%(msg.target, msg.user.nick, msg.line)
!
def print_connected(server):
! print "Connected to %s!"%server.servername
!
def print_connection_error(server):
! print "Connection error on %s!"%server.servername
!
def print_connecting_error(server):
! print "Error connecting to %s!"%server.servername
def main():
! pybot.init() # Initialize globaly acessible data
! pybot.hooks.register("Command", print_cmd)
! pybot.hooks.register("Message", print_msg)
! pybot.hooks.register("Notice", print_not)
! pybot.hooks.register("Connected", print_connected)
! pybot.hooks.register("ConnectionError", print_connection_error)
! pybot.hooks.register("ConnectingError", print_connecting_error)
! pybot.modls.load("options")
! pybot.modls.load("modulecontrol")
! ret = pybot.main.loop()
! sys.exit(ret)
if __name__ == "__main__":
! main()
# vim:ts=4:sw=4:et
--- 28,94 ----
def print_cmd(cmd):
! print "Command(%s): %s"%(cmd.cmd, cmd.line)
def print_msg(msg):
! print "Message(%s/%s): %s"%(msg.target, msg.user.nick, msg.line)
def print_not(msg):
! print "Notice(%s/%s): %s"%(msg.target, msg.user.nick, msg.line)
def print_connected(server):
! print "Connected to %s!"%server.servername
def print_connection_error(server):
! print "Connection error on %s!"%server.servername
def print_connecting_error(server):
! print "Error connecting to %s!"%server.servername
!
! USAGE = """\
! Usage: pybot.py [OPTIONS]
!
! Options:
! -c Enable console
! -d Enable debug mode
! -h Show this message
!
! Examples:
! repsys submit https://repos/svn/cnc/snapshot/foo 14800
! repsys submit -l https://repos
! """
!
! def parse_options():
! try:
! opts, args = getopt.getopt(sys.argv[1:], "cdh", ["help"])
! except getopt.GetoptError, e:
! sys.exit("error: "+e.msg)
! class Options: pass
! obj = Options()
! obj.console = 0
! obj.debug = 0
! for opt, val in opts:
! if opt == "-c":
! obj.console = 1
! elif opt == "-d":
! obj.debug = 1
! elif opt in ["-h", "--help"]:
! sys.stdout.write(USAGE)
! sys.exit(1)
! return obj
def main():
! pybot.init() # Initialize globaly acessible data
! opts = parse_options()
! if opts.console:
! pybot.servers.add_console()
! if opts.debug:
! pybot.hooks.register("Command", print_cmd)
! pybot.hooks.register("Message", print_msg)
! pybot.hooks.register("Notice", print_not)
! pybot.hooks.register("Connected", print_connected)
! pybot.hooks.register("ConnectionError", print_connection_error)
! pybot.hooks.register("ConnectingError", print_connecting_error)
! pybot.modls.load("options")
! pybot.modls.load("modulecontrol")
! ret = pybot.main.loop()
! sys.exit(ret)
if __name__ == "__main__":
! main()
# vim:ts=4:sw=4:et
Index: server.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/server.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** server.py 4 Dec 2001 00:57:38 -0000 1.2
--- server.py 9 May 2003 20:18:36 -0000 1.3
***************
*** 18,25 ****
from errno import EINPROGRESS, EALREADY, EWOULDBLOCK
! from thread import allocate_lock
from select import select
from string import split
! from time import time
import socket
--- 18,25 ----
from errno import EINPROGRESS, EALREADY, EWOULDBLOCK
! from thread import allocate_lock, start_new_thread
from select import select
from string import split
! from time import time, sleep
import socket
***************
*** 36,41 ****
def add(self, servername):
! self.servers.append(Server(self, servername))
def remove(self, servername):
for i in range(len(self.servers)):
--- 36,44 ----
def add(self, servername):
! self.servers.append(Server(servername))
+ def add_console(self):
+ self.servers.append(ConsoleServer())
+
def remove(self, servername):
for i in range(len(self.servers)):
***************
*** 51,60 ****
return self.servers
! class Server:
! def __init__(self, bot, servername):
self.changeserver(servername)
- self._bot = bot
self._inbuffer = ""
- self._inlines = []
self._outlines = []
self._outlines_lock = allocate_lock()
--- 54,100 ----
return self.servers
! class BaseServer:
! def __init__(self, servername):
! self.servername = servername
! self.killed = 0
! self._inlines = []
! self.user = User()
!
! def interaction(self):
! pass
!
! def changeserver(self, servername):
! pass
!
! def kill(self):
! pass
!
! def reconnect(self):
! pass
!
! def sendcmd(self, prefix, cmd, *params, **kw):
! pass
!
! def sendmsg(self, target, nick, *params, **kw):
! pass
!
! def readline(self):
! """Return one line from the buffer (and remove it).
!
! This method is not thread safe, since it must be called only
! by the main loop.
! """
! line = None
! if len(self._inlines) > 0:
! line = self._inlines[0]
! del self._inlines[0]
! return line
!
! class Server(BaseServer):
! def __init__(self, servername):
! BaseServer.__init__(self, servername)
!
self.changeserver(servername)
self._inbuffer = ""
self._outlines = []
self._outlines_lock = allocate_lock()
***************
*** 64,75 ****
self._socket.setblocking(0)
self._timeout = 0
- self.connected = 0
self._connect = 1
self._reconnect = 0
! self.killed = 0
! self.user = User()
def interaction(self):
! if not self.connected:
if self._timeout:
self._timeout = self._timeout-1
--- 104,113 ----
self._socket.setblocking(0)
self._timeout = 0
self._connect = 1
self._reconnect = 0
! self._connected = 0
def interaction(self):
! if not self._connected:
if self._timeout:
self._timeout = self._timeout-1
***************
*** 84,88 ****
self._disconnect()
return
! self.connected = 1
pybot.hooks.call("Connected", self)
else:
--- 122,126 ----
self._disconnect()
return
! self._connected = 1
pybot.hooks.call("Connected", self)
else:
***************
*** 157,161 ****
except:
pass
! self.connected = 0
self._outlines = []
--- 195,199 ----
except:
pass
! self._connected = 0
self._outlines = []
***************
*** 165,184 ****
def reconnect(self):
! if self.connected:
self._reconnect = 1
self._timeout = CONNECTDELAY
- def readline(self):
- """Return one line from the buffer (and remove it).
-
- This method is not thread safe, since it must be called only
- by the main loop.
- """
- line = None
- if len(self._inlines) > 0:
- line = self._inlines[0]
- del self._inlines[0]
- return line
-
def sendline(self, line, priority=50, outhooks=1):
"""Send one line for the server.
--- 203,210 ----
def reconnect(self):
! if self._connected:
self._reconnect = 1
self._timeout = CONNECTDELAY
def sendline(self, line, priority=50, outhooks=1):
"""Send one line for the server.
***************
*** 231,234 ****
--- 257,310 ----
subline = linemask%subline
self.sendline(subline, priority, outhooks)
+
+ from cmd import Cmd
+
+ class ConsoleServer(BaseServer, Cmd):
+ def __init__(self):
+ BaseServer.__init__(self, "console")
+ self.user.set("pybot", "pybot", "console")
+
+ Cmd.__init__(self)
+ self.prompt = "pybot> "
+ start_new_thread(self.cmdloop, ())
+ del Cmd.do_help
+
+ self._outlines = []
+ self._outlines_lock = allocate_lock()
+
+ def sendcmd(self, prefix, cmd, *params, **kw):
+ outline = "[CMD] %s %s" % \
+ (cmd, buildanswer(params, None, self.user.nick))
+ self._outlines_lock.acquire()
+ self._outlines.append(outline)
+ self._outlines_lock.release()
+
+ def sendmsg(self, target, nick, *params, **kw):
+ outline = "[MSG] %s" % buildanswer(params, target, nick)
+ self._outlines_lock.acquire()
+ self._outlines.append(outline)
+ self._outlines_lock.release()
+
+ def show_lines(self):
+ self._outlines_lock.acquire()
+ for line in self._outlines:
+ print line
+ self._outlines = []
+ self._outlines_lock.release()
+
+ def default(self, line):
+ if line == "EOF":
+ print
+ return 1
+ inline = ":master!master@console PRIVMSG pybot :%s" % line
+ self._inlines.append(inline)
+ sleep(0.5)
+ self.show_lines()
+
+ def emptyline(self):
+ pass
+
+ def postloop(self):
+ pybot.main.quit = 1
# vim:ts=4:sw=4:et
--- core.py DELETED ---
|