summaryrefslogtreecommitdiff
path: root/scripts/python/pyexec.py
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2006-10-29 09:15:50 +0000
committerSebastien Helleu <flashcode@flashtux.org>2006-10-29 09:15:50 +0000
commit812ed965e9cc364008dbdcb88203125b9bc54621 (patch)
treeadfef73064e0e9756a6de46f254414fc8785c3fd /scripts/python/pyexec.py
parentb84f75eba6f7149ca398bfe71dad7695c9898f66 (diff)
downloadweechat-812ed965e9cc364008dbdcb88203125b9bc54621.zip
Added "pyexec" script
Diffstat (limited to 'scripts/python/pyexec.py')
-rw-r--r--scripts/python/pyexec.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/scripts/python/pyexec.py b/scripts/python/pyexec.py
new file mode 100644
index 000000000..53b3f6bee
--- /dev/null
+++ b/scripts/python/pyexec.py
@@ -0,0 +1,50 @@
+"""
+ PyExec: Python code execution script for WeeChat
+ Author: Christian Taylor <cht@chello.at>
+ License: GPL version 2 or later
+"""
+
+version = "0.1"
+helptext = """ The WeeChat script-API is imported into the global namespace, you can
+ call all API functions (for instance get_nick_info) directly. The modules
+ "sys", "os" and "math" are imported by default.
+ Any occurance of ";; " is treated as a newline.
+
+ For automatic string conversion, use:
+ "send" instead of "command"
+ "echo" instead of "prnt" (prints only to current buffer)
+ (also provided: "echo_server", "echo_infobar")
+
+ Examples:
+ /pyexec for i in range(3): send(i+1);; echo("Done")
+ /pyexec for nick in ["nick1", "nick2"]: send("/op " + nick)
+"""
+
+
+from weechat import *
+import sys, os, math
+
+register("PyExec", version, "", "Run Python code in WeeChat")
+add_command_handler("pyexec", "pyexec", " Runs Python code directly from the WeeChat command line.", "[Python code]", helptext)
+
+def echo(text):
+ return prnt(str(text))
+
+def echo_server(text):
+ return print_server(str(text))
+
+def echo_infobar(time, text):
+ return print_infobar(time, str(text))
+
+def send(text):
+ return command(str(text))
+
+def pyexec(server, pycode):
+ try:
+ for pyline in pycode.split(";; "):
+ exec pyline
+ except:
+ (e_type, e_value, e_trace) = sys.exc_info()
+ prnt("PyExec: %s [%s] in line: \"%s\"" % (e_type, e_value, pyline))
+
+ return PLUGIN_RC_OK