FastRPC-Netcat
FastRPC-Netcat is a XML-RPC/FastRPC/MySQL console for developers/admins written in Python. It uses Python-like syntax, so you can use expressions from Python, print out only part of some big result and so on.
Usage
fastrpc-netcat(1) USER COMMANDS fastrpc-netcat(1) NAME fastrpc-netcat SYNOPSIS fastrpc-netcat [{HOST [PORT]} | http://HOST:PORT/PATH}] DESCRIPTION XML-RPC/FastRPC/MySQL console with Python-like syntax OPTIONS HOST RPC server hostname PORT RPC server port PATH RPC server path, default is /RPC2 (when not using URL notation) EXAMPLES Connect to RPC server on http://10.0.16.40:3990/RPC2: fastrpc-netcat 10.0.16.40 3990 Connect to RPC server on http://10.0.16.40:9999/rpc.php: fastrpc-netcat http://10.0.16.40:9999/rpc.php STARTUP On startup fastrpc-netcat tries to import fn.py from PYTHONPATH. On success symbols from fn.py are available as fn.SYMBOLNAME. INTERACTIVE CONSOLE When fastrpc-netcat is executed, it spawns an interactive console. This interactive console uses Python-like syntax. By default the expression entered is evaluated as Python expression and printed out, for example: fastrpc-netcat[18107] > [1,2,3,4,5] writes out: result = array ( [0] int = 1 [1] int = 2 [2] int = 3 [3] int = 4 [4] int = 5 ) Method returned after 121.117 microseconds If we want to write expression out in Python syntax, we can use: fastrpc-netcat[18107] > [1,2,3,4,5,{"a":"b"}]* and it writes out: [1, 2, 3, 4, 5, {’a’: ’b’}] Method returned after 121.117 microseconds This console also supports one-line Python sentences, if you prefix it with exclamation mark: fastrpc-netcat[18107] > !for a in xrange(5): print "Hello %s!" % a produces this output: Hello 0! Hello 1! Hello 2! Hello 3! Hello 4! To connect to (another) RPC server and call it ’test’, we use: fastrpc-netcat[18107] > connect test 127.0.0.1 9999 New client is now known as test fastrpc-netcat[18107] > then we can call methods: fastrpc-netcat[18107] > test.system.listMethods() result = array ( [0] string = "session.check" [1] string = "session.cleanup" [2] string = "session.create" [3] string = "session.getMetadata" [4] string = "session.remove" [5] string = "session.setMetadata" [6] string = "session.stat" [7] string = "session.update" [8] string = "system.listMethods" [9] string = "system.methodHelp" [10] string = "system.methodSignature" [11] string = "system.multicall" ) Method returned after 1.036 milliseconds fastrpc-netcat[18107] > To connect to database and call it ’testdb’, we use: fastrpc-netcat[18107] > connectdb testdb 127.0.0.1 mysql root mysecretpassword New database client is now known as testdb fastrpc-netcat[18107] > and now we can do some SQL query: fastrpc-netcat[18107] > testdb.execute("SELECT DISTINCT Host FROM user") result = array ( [0] struct = { string Host = "%" } [1] struct = { string Host = "192.168.1.99" } [2] struct = { string Host = "ingwe" } [3] struct = { string Host = "localhost" } [4] struct = { string Host = "thingol" } ) Method returned after 420.048 milliseconds we can work with result as in Python: fastrpc-netcat[18107] > testdb.execute("SELECT DISTINCT Host FROM user")[0]["Host"] result = string "%" Method returned after 74.213 milliseconds COMMANDS IN INTERACTIVE CONSOLE connect Creates new connection to RPC server: connect [NAME] {HOST} {PORT} connect [NAME] http://{HOST}:{PORT}/{URL} connectdb Creates new connection to MySQL database: connectdb {NAME} {HOST} {DBNAME} {USER} [PASSWORD] timeout Sets RPC read timeout: timeout {MILLISECONDS} charset Sets input/output charset: charset {CHARSET} help Prints help: help [METHOD] {METHOD} -h exit Exits fastrpc-netcat console: exit [RESULT] quit [RESULT] import Imports python module: import sys import datetime FILE() Readfile function, returns file contents as fastrpc binary: FILE("{FILENAME}") when bare string needed, use FILE(...).data Binary() Creates binary type (Base64 for XML-RPC, Binary for FastRPC): Binary({STRING}) DateTime() Creates datetime type: DateTime({TIMESTAMP|STRING}) Boolean() Creates boolean type: Boolean({BOOLEAN|INTEGER}) FILES ~/.fastrpc-netcatrc The individual startup file ~/.fastrpc-netcat_history Console history file fn.py (in PYTHONPATH) The individual methods and variables file /usr/share/fastrpc-netcat/COPYING License information AUTHOR Eduard Veleba (eduard.veleba (at) firma.seznam.cz) LICENSE Fastrpc-netcat is released under GNU General Public License version 3. version 0.1 September 27, 2007 fastrpc-netcat(1)