| 1 | [[libtorrentMirror]] |
| 2 | |
| 3 | If you've ever used the xmlrpc utility tool from the xmlrpc-c project, then you'll recognize this as the equivalent except that it sends xmlrpc requests over scgi instead of http. It also follows the same command line argument syntax as xmlrpc. |
| 4 | |
| 5 | For example: |
| 6 | {{{ |
| 7 | ~# ./xmlrpc2scgi.py -p 'scgi://localhost:33000' d.get_name s/1BEB405E5066392CDAE96EEF9F82F7D83C2343E9 |
| 8 | Gotan Project - Lunatico (2006) |
| 9 | }}} |
| 10 | |
| 11 | {{{ |
| 12 | ~# ./xmlrpc2scgi.py 'scgi://localhost:33000' d.get_name s/1BEB405E5066392CDAE96EEF9F82F7D83C2343E9 |
| 13 | <?xml version="1.0" encoding="UTF-8"?> |
| 14 | <methodResponse> |
| 15 | <params> |
| 16 | <param><value><string>Gotan Project - Lunatico (2006)</string></value></param> |
| 17 | </params> |
| 18 | </methodResponse> |
| 19 | }}} |
| 20 | |
| 21 | So this can be a tool for testing that xmlrpc is setup and working as well as for scripting in bash or some other scripting language. |
| 22 | |
| 23 | But if you're using python then you get something extra: |
| 24 | {{{ |
| 25 | [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 |
| 26 | Type "help", "copyright", "credits" or "license" for more information. |
| 27 | >>> import xmlrpc2scgi as xs |
| 28 | >>> rtc = xs.RTorrentXMLRPCClient('scgi://localhost:33000') |
| 29 | >>> infohash = rtc.download('completed')[0] |
| 30 | Traceback (most recent call last): |
| 31 | File "<stdin>", line 1, in <module> |
| 32 | File "xmlrpc2scgi.py", line 175, in __call__ |
| 33 | return do_scgi_xmlrpc_request_py(self.url, self.methodname, args) |
| 34 | File "xmlrpc2scgi.py", line 157, in do_scgi_xmlrpc_request_py |
| 35 | return xmlrpclib.loads(xmlresp)[0][0] |
| 36 | File "/usr/lib/python2.5/xmlrpclib.py", line 1132, in loads |
| 37 | return u.close(), u.getmethodname() |
| 38 | File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close |
| 39 | raise Fault(**self._stack[0]) |
| 40 | xmlrpclib.Fault: <Fault -506: "Method 'download' not defined"> |
| 41 | >>> infohash = rtc.download_list('completed')[0] |
| 42 | Traceback (most recent call last): |
| 43 | File "<stdin>", line 1, in <module> |
| 44 | File "xmlrpc2scgi.py", line 175, in __call__ |
| 45 | return do_scgi_xmlrpc_request_py(self.url, self.methodname, args) |
| 46 | File "xmlrpc2scgi.py", line 157, in do_scgi_xmlrpc_request_py |
| 47 | return xmlrpclib.loads(xmlresp)[0][0] |
| 48 | File "/usr/lib/python2.5/xmlrpclib.py", line 1132, in loads |
| 49 | return u.close(), u.getmethodname() |
| 50 | File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close |
| 51 | raise Fault(**self._stack[0]) |
| 52 | xmlrpclib.Fault: <Fault -503: 'Could not find view.'> |
| 53 | >>> infohash = rtc.download_list('complete')[0] |
| 54 | >>> print rtc.d.get_name(infohash), 'is on host', rtc.system.hostname() |
| 55 | Apoptygma Berzerk - 7 [2002 'digitally remastered'] is on host datastore |
| 56 | |
| 57 | }}} |
| 58 | |
| 59 | So scripting becomes much easier in python as well as error/exception control. |
| 60 | |
| 61 | Download xmlrpc2scgi here: |
| 62 | [http://static.jmk.hu/libtorrent.rakshasa.no/downloads/xmlrpc2scgi.py xmlrpc2scgi.py] |