Changeset 1188

Show
Ignore:
Timestamp:
08/25/06 21:27:53 (2 years ago)
Author:
athomas
Message:

XmlRpcPlugin:

Applied patch submitted by steffenp@gmx.de, with some modifications. This adds
ticket.getRecentChanges() and ticket.getAvailableActions(). Changed
wiki.putAttachment() to be completely compatible with WikiRPC, and added
wiki.putAttachmentEx() for Trac specific extensions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • xmlrpcplugin/0.10/tracrpc/api.py

    r848 r1188  
    163163        for provider in self.method_handlers: 
    164164            for candidate in provider.xmlrpc_methods(): 
     165                self.env.log.debug(candidate) 
    165166                p = Method(provider, *candidate) 
    166167                if p.name == method: 
  • xmlrpcplugin/0.10/tracrpc/ticket.py

    r1154 r1188  
    22from trac.core import * 
    33from tracrpc.api import IXMLRPCHandler, expose_rpc 
     4from tracrpc.util import to_timestamp 
    45import trac.ticket.model as model 
    56import trac.ticket.query as query 
     7from trac.ticket.api import TicketSystem 
    68 
    79import pydoc 
     
    2022    def xmlrpc_methods(self): 
    2123        yield ('TICKET_VIEW', ((list,), (list, str)), self.query) 
     24        yield ('TICKET_VIEW', ((list, xmlrpclib.DateTime),), self.getRecentChanges) 
     25        yield ('TICKET_VIEW', ((list, int),), self.getAvailableActions) 
    2226        yield ('TICKET_VIEW', ((list, int),), self.get) 
    2327        yield ('TICKET_CREATE', ((int, str, str), (int, str, str, dict)), self.create) 
     
    4145            out.append(t['id']) 
    4246        return out 
     47 
     48    def getRecentChanges(self, req, since): 
     49        """Returns a list of IDs of tickets that have changed since timestamp.""" 
     50        since = to_timestamp(since) 
     51        db = self.env.get_db_cnx() 
     52        cursor = db.cursor() 
     53        cursor.execute('SELECT id FROM ticket' 
     54                       ' WHERE changetime >= %s', (since,)) 
     55        result = [] 
     56        for row in cursor: 
     57            result.append(int(row[0])) 
     58        return result 
     59 
     60    def getAvailableActions(self, req, id): 
     61        """Returns the actions that can be performed on the ticket.""" 
     62        ticketSystem = TicketSystem(self.env) 
     63        t = model.Ticket(self.env, id) 
     64        return ticketSystem.get_available_actions(t, req.perm) 
    4365 
    4466    def get(self, req, id): 
  • xmlrpcplugin/0.10/tracrpc/wiki.py

    r1161 r1188  
    1313from trac.attachment import Attachment 
    1414from tracrpc.api import IXMLRPCHandler, expose_rpc 
     15from tracrpc.util import to_timestamp 
    1516 
    1617class WikiRPC(Component): 
     
    3839        yield ('WIKI_VIEW', ((list, str),), self.listAttachments) 
    3940        yield ('WIKI_VIEW', ((xmlrpclib.Binary, str),), self.getAttachment) 
    40         yield ('WIKI_MODIFY', ((bool, str, str, xmlrpclib.Binary), 
    41                                (str, str, str, xmlrpclib.Binary, bool)), self.putAttachment) 
     41        yield ('WIKI_MODIFY', ((bool, str, xmlrpclib.Binary),), self.putAttachment) 
     42        yield ('WIKI_MODIFY', ((bool, str, str, str, xmlrpclib.Binary), 
     43                               (bool, str, str, str, xmlrpclib.Binary, bool)), 
     44                               self.putAttachmentEx) 
    4245        yield ('WIKI_DELETE', ((bool, str),), self.deleteAttachment) 
    4346        yield ('WIKI_VIEW', ((list, str),), self.listLinks) 
    4447        yield ('WIKI_VIEW', ((str, str),), self.wikiToHtml) 
    45  
    46     def _to_timestamp(self, datetime): 
    47         import time 
    48         return time.mktime(time.strptime(datetime.value, '%Y%m%dT%H:%M:%S')) 
    4948 
    5049    def _page_info(self, name, time, author, version): 
     
    5453    def getRecentChanges(self, req, since): 
    5554        """ Get list of changed pages since timestamp """ 
    56         since = self._to_timestamp(since) 
     55        since = to_timestamp(since) 
    5756        db = self.env.get_db_cnx() 
    5857        cursor = db.cursor() 
     
    126125        return xmlrpclib.Binary(attachment.open().read()) 
    127126 
    128     def putAttachment(self, req, path, data, replace=True): 
    129         """ (over)writes an attachment. For compatibility with WikiRPC, if 
    130         replace=True then the return type is a boolean, otherwise it is the 
    131         attachment filename. """ 
     127    def putAttachment(self, req, path, data): 
     128        """ (over)writes an attachment. Returns True if successful. 
     129         
     130        This method is compatible with WikiRPC.  `putAttachmentEx` has a more 
     131        extensive set of (Trac-specific) features. """ 
    132132        pagename, filename = posixpath.split(path) 
     133        self.putAttachmentEx(req, pagename, filename, None, data) 
     134        return True 
     135 
     136    def putAttachmentEx(self, req, pagename, filename, description, data, replace=True): 
     137        """ Attach a file to a Wiki page. Returns the (possibly transformed) 
     138        filename of the attachment. 
     139         
     140        Use this method if you don't care about WikiRPC compatibility. """ 
    133141        if not WikiPage(self.env, pagename).exists: 
    134142            raise TracError, 'Wiki page "%s" does not exist' % pagename 
     
    141149        attachment = Attachment(self.env, 'wiki', pagename) 
    142150        attachment.author = req.authname or 'anonymous' 
     151        attachment.description = description 
    143152        attachment.insert(filename, StringIO(data.data), len(data.data)) 
    144         if replace: 
    145             return True 
    146         else: 
    147             return attachment.filename 
     153        return attachment.filename 
    148154 
    149155    def deleteAttachment(self, req, path):