Changeset 820

Show
Ignore:
Timestamp:
06/05/06 22:15:24 (2 years ago)
Author:
athomas
Message:

XmlRpcPlugin:

  • Applied some patches provided by Steffen Pingel, thanks.
  • Wiki and ticket attachments can now be optionally replaced, or a new filename generated and returned.
Files:

Legend:

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

    r808 r820  
    8787        if result is None: 
    8888            result = 0 
     89        elif isinstance(result, dict): 
     90            pass 
    8991        elif not isinstance(result, basestring): 
    9092            # Try and convert result to a list 
  • xmlrpcplugin/0.10/tracrpc/ticket.py

    r808 r820  
    77import pydoc 
    88import xmlrpclib 
     9from StringIO import StringIO 
    910 
    1011class TicketRPC(Component): 
     
    2627        yield ('TICKET_VIEW', ((list, int),), self.listAttachments) 
    2728        yield ('TICKET_VIEW', ((xmlrpclib.Binary, int, str),), self.getAttachment) 
    28         yield ('TICKET_APPEND', ((bool, int, str, xmlrpclib.Binary),), self.putAttachment) 
     29        yield ('TICKET_APPEND', 
     30               ((str, int, str, xmlrpclib.Binary, bool), 
     31                (str, int, str, xmlrpclib.Binary)), 
     32               self.putAttachment) 
     33        yield ('TICKET_ADMIN', ((bool, int, str),), self.deleteAttachment) 
    2934 
    3035    # Exported methods 
     
    5964            t[k] = v 
    6065        t.save_changes(req.authname, comment) 
    61         return self.get(t.id) 
     66        return self.get(req, t.id) 
    6267 
    6368    def delete(self, req, id): 
     
    6671        t.delete() 
    6772 
    68     def changeLog(self, req, id, when = 0): 
    69         t = model.Ticket(self.env, id
     73    def changeLog(self, req, id, when=0): 
     74        t = model.Ticket(self.env, id, when
    7075        return t.get_changelog() 
    7176    # Use existing documentation from Ticket model 
     
    8186        return xmlrpclib.Binary(attachment.open().read()) 
    8287 
    83     def putAttachment(self, req, ticket, filename, data): 
    84         """ (over)writes an attachment. """ 
    85         if not Ticket(self.env, ticket).exists: 
     88    def putAttachment(self, req, ticket, filename, data, replace=True): 
     89        """ Add an attachment, optionally (and defaulting to) overwriting an 
     90        existing one. Returns filename.""" 
     91        if not model.Ticket(self.env, ticket).exists: 
    8692            raise TracError, 'Ticket "%s" does not exist' % ticket 
     93        if replace: 
     94            try: 
     95                attachment = Attachment(self.env, 'ticket', ticket, filename) 
     96                attachment.delete() 
     97            except TracError: 
     98                pass 
    8799        attachment = Attachment(self.env, 'ticket', ticket) 
     100        attachment.author = req.authname or 'anonymous' 
    88101        attachment.insert(filename, StringIO(data.data), len(data.data)) 
     102        return attachment.filename 
     103 
     104    def deleteAttachment(self, req, ticket, filename): 
     105        """ Delete an attachment. """ 
     106        if not model.Ticket(self.env, ticket).exists: 
     107            raise TracError('Ticket "%s" does not exists' % ticket) 
     108        attachment = Attachment(self.env, 'ticket', ticket, filename) 
     109        attachment.delete() 
    89110        return True 
    90111 
     
    115136            for k in cls_attributes: 
    116137                attributes[k] = getattr(i, k) 
    117             return attr 
     138            return attributes 
    118139        get.__doc__ = """ Get a ticket %s. """ % cls.__name__.lower() 
    119140 
     
    170191 
    171192        def create(self, req, name, value): 
    172             self._updateHelper(name, value).insert() 
     193            i = cls(self.env) 
     194            i.value = value 
     195            i.insert() 
    173196        create.__doc__ = """ Create a new ticket %s with the given value. """ % cls.__name__.lower() 
    174197 
     
    178201 
    179202        def _updateHelper(self, req, name, value): 
    180             i = cls(self.env) 
    181             i.name = name 
     203            i = cls(self.env, name) 
    182204            i.value = value 
    183205            return i 
  • xmlrpcplugin/0.10/tracrpc/wiki.py

    r808 r820  
    3838        yield ('WIKI_VIEW', ((list, str),), self.listAttachments) 
    3939        yield ('WIKI_VIEW', ((xmlrpclib.Binary, str),), self.getAttachment) 
    40         yield ('WIKI_MODIFY', ((bool, str, str, xmlrpclib.Binary),), self.putAttachment) 
     40        yield ('WIKI_MODIFY', ((bool, str, str, xmlrpclib.Binary), 
     41                               (str, str, str, xmlrpclib.Binary, bool)), self.putAttachment) 
     42        yield ('WIKI_DELETE', ((bool, str),), self.deleteAttachment) 
    4143        yield ('WIKI_VIEW', ((list, str),), self.listLinks) 
    4244 
     
    123125        return xmlrpclib.Binary(attachment.open().read()) 
    124126 
    125     def putAttachment(self, req, path, data): 
    126         """ (over)writes an attachment. """ 
     127    def putAttachment(self, req, path, data, replace=True): 
     128        """ (over)writes an attachment. For compatibility with WikiRPC, if 
     129        replace=True then the return type is a boolean, otherwise it is the 
     130        attachment filename. """ 
    127131        pagename, filename = posixpath.split(path) 
    128132        if not WikiPage(self.env, pagename).exists: 
    129133            raise TracError, 'Wiki page "%s" does not exist' % pagename 
     134        if replace: 
     135            try: 
     136                attachment = Attachment(self.env, 'wiki', pagename, filename) 
     137                attachment.delete() 
     138            except TracError: 
     139                pass 
    130140        attachment = Attachment(self.env, 'wiki', pagename) 
     141        attachment.author = req.authname or 'anonymous' 
    131142        attachment.insert(filename, StringIO(data.data), len(data.data)) 
     143        if replace: 
     144            return True 
     145        else: 
     146            return attachment.filename 
     147 
     148    def deleteAttachment(self, req, path): 
     149        """ Delete an attachment. """ 
     150        pagename, filename = posixpath.split(path) 
     151        if not WikiPage(self.env, pagename).exists: 
     152            raise TracError, 'Wiki page "%s" does not exist' % pagename 
     153        attachment = Attachment(self.env, 'wiki', pagename, filename) 
     154        attachment.delete() 
    132155        return True 
    133156