Changes between Version 14 and Version 15 of XmlRpcPlugin
- Timestamp:
- Dec 27, 2005, 11:19:34 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
XmlRpcPlugin
v14 v15 17 17 == API == 18 18 19 The API is quite basic, but has a few magic features to make life a bit easier for the general case. 20 21 To export functions via the XML-RPC, a Trac component simply needs to implement the following interface: 22 23 {{{ 24 #!python 25 class IXMLRPCHandler(Interface): 26 def get_xmlrpc_functions(): pass 27 }}} 28 29 The {{{get_xmlrpc_functions()}}} method returns an iterable of tuples in the form: 30 31 {{{ 32 (permission, callable[, name[, description]]) 33 }}} 34 35 Where these fields are in the following form: 36 37 ||'''Field'''||'''Description'''|| 38 ||{{{permission}}}||The Trac permission required to be able to use this function. Additionally, to use the XML-RPC interface to Trac users must have the {{{XML_RPC}}} Trac permission. Once this has been granted, the permissions of each exported function apply. eg. {{{WIKI_ADMIN}}}.|| 39 ||{{{callable}}}||A method or function. The function signature can have an optional first parameter named {{{req}}} which, if present, will be the Trac request object.|| 40 ||{{{name}}}||If not provided, the function will be exported with the name {{{__module__.__name__}}}.|| 41 ||{{{description}}}||If not provided, the functions DOC string will be used.|| 42 43 See [[ref(API Usage)]] for an example. 19 See the [source:xmlrpcplugin/0.9/tracrpc/api.py source] for API usage. 44 20 45 21 == Todo == 46 22 47 At the moment only the ticket interface is relatively complete. The milestone and component interfaces are just stubs, and no other sections have been implemented.23 [http://www.jspwiki.org/Wiki.jsp?page=WikiRPCInterface2 WikiRPC API] is complete, mostly thanks to [wiki:mgood]. 48 24 49 [wiki:mgood] has proposed using the [http://www.jspwiki.org/Wiki.jsp?page=WikiRPCInterface2 WikiRPC API] for interacting with the Wiki which seems like a good idea to me.25 Ticket API is also complete, with the following types exported: component, version, milestone, type, status, resolution, priority and severity. 50 26 51 So the outstanding tasks are milestone, component, wiki,search, roadmap, timeline, user management (?), plugin management (?)...plus probably more.27 So the outstanding tasks are search, roadmap, timeline, user management (?), plugin management (?)...plus probably more. 52 28 53 29 == Installation == … … 59 35 # python setup.py bdist_egg 60 36 # cp dist/*.egg /srv/trac/env/plugins 37 }}} 38 39 You will also probably need to enable the plugin in your environments trac.ini: 40 41 {{{ 42 [components] 43 tracrpc.* = enabled 61 44 }}} 62 45 … … 82 65 83 66 84 Obtain a list of XML-RPC exported functions available to my user:67 Obtain and print a list of XML-RPC exported functions available to my user: 85 68 86 69 {{{ … … 89 72 90 73 server = xmlrpclib.ServerProxy("http://athomas:password@localhost/trac-dev/login/RPC2") 91 print server.tracrpc.api.list_xmlrpc_functions() 74 for method in server.system.listMethods(): 75 print method 76 print '\n'.join([' ' + x for x in server.system.methodHelp(method).split('\n')]) 77 print 78 print 92 79 }}} 93 80 94 List all tickets that are owned by athomas: 81 List all tickets that are owned by athomas, using the XML-RPC multicall system 82 to issue multiple RPC calls with one HTTP request: 95 83 96 84 {{{ … … 99 87 100 88 server = xmlrpclib.ServerProxy("http://athomas:password@localhost/trac-dev/login/RPC2") 101 print server.tracrpc.ticket.query_tickets("owner=athomas") 89 tickets = server.ticket.query("owner=athomas") 90 print '\n'.join(map(str, server.system.multicall([{'methodName' : 'ticket.get', 'params' : [ticket]} for ticket in tickets]))) 102 91 }}} 103 92 104 93 === API Usage === 105 Export a "hello world' function, as well as a less-than-safe function.106 94 107 {{{ 108 #!python 109 from tracrpc.api import IXMLRPCProvider 110 from trac.core import Component, implements 111 112 class HelloWorld(Component): 113 implements(IXMLRPCProvider) 114 115 def hello_world(self): 116 """ Hello world! """ 117 return "Hello world" 118 119 def delete_whole_system(self, req): 120 """ This is the safest function to export. """ 121 req.assert_permission('SANITY_CHECK') 122 import os 123 os.system("rm -rf /") 124 125 def get_xmlrpc_functions(self): 126 yield ('WIKI_VIEW', self.hello_world, 'hello_world') 127 yield ('WIKI_ADMIN', self.delete_whole_system) 128 }}} 129 130 The method {{{hello_world()}}} is exported with the name "hello_world", as 131 opposed to the default of combining the current module name with the function 132 name. 133 134 The {{{delete_whole_system()}}} method uses the optional {{{req}}} argument to 135 enforce extra permission requirements. 95 See the [source:xmlrpcplugin/0.9/tracrpc/api.py source] for details. 136 96 137 97 == Screenshot ==