Changeset 820
- Timestamp:
- 06/05/06 22:15:24 (2 years ago)
- Files:
-
- xmlrpcplugin/0.10/tracrpc/api.py (modified) (1 diff)
- xmlrpcplugin/0.10/tracrpc/ticket.py (modified) (8 diffs)
- xmlrpcplugin/0.10/tracrpc/wiki.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
xmlrpcplugin/0.10/tracrpc/api.py
r808 r820 87 87 if result is None: 88 88 result = 0 89 elif isinstance(result, dict): 90 pass 89 91 elif not isinstance(result, basestring): 90 92 # Try and convert result to a list xmlrpcplugin/0.10/tracrpc/ticket.py
r808 r820 7 7 import pydoc 8 8 import xmlrpclib 9 from StringIO import StringIO 9 10 10 11 class TicketRPC(Component): … … 26 27 yield ('TICKET_VIEW', ((list, int),), self.listAttachments) 27 28 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) 29 34 30 35 # Exported methods … … 59 64 t[k] = v 60 65 t.save_changes(req.authname, comment) 61 return self.get( t.id)66 return self.get(req, t.id) 62 67 63 68 def delete(self, req, id): … … 66 71 t.delete() 67 72 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) 70 75 return t.get_changelog() 71 76 # Use existing documentation from Ticket model … … 81 86 return xmlrpclib.Binary(attachment.open().read()) 82 87 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: 86 92 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 87 99 attachment = Attachment(self.env, 'ticket', ticket) 100 attachment.author = req.authname or 'anonymous' 88 101 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() 89 110 return True 90 111 … … 115 136 for k in cls_attributes: 116 137 attributes[k] = getattr(i, k) 117 return attr 138 return attributes 118 139 get.__doc__ = """ Get a ticket %s. """ % cls.__name__.lower() 119 140 … … 170 191 171 192 def create(self, req, name, value): 172 self._updateHelper(name, value).insert() 193 i = cls(self.env) 194 i.value = value 195 i.insert() 173 196 create.__doc__ = """ Create a new ticket %s with the given value. """ % cls.__name__.lower() 174 197 … … 178 201 179 202 def _updateHelper(self, req, name, value): 180 i = cls(self.env) 181 i.name = name 203 i = cls(self.env, name) 182 204 i.value = value 183 205 return i xmlrpcplugin/0.10/tracrpc/wiki.py
r808 r820 38 38 yield ('WIKI_VIEW', ((list, str),), self.listAttachments) 39 39 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) 41 43 yield ('WIKI_VIEW', ((list, str),), self.listLinks) 42 44 … … 123 125 return xmlrpclib.Binary(attachment.open().read()) 124 126 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. """ 127 131 pagename, filename = posixpath.split(path) 128 132 if not WikiPage(self.env, pagename).exists: 129 133 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 130 140 attachment = Attachment(self.env, 'wiki', pagename) 141 attachment.author = req.authname or 'anonymous' 131 142 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() 132 155 return True 133 156
