~ubuntuone-control-tower/ubuntuone-storage-protocol/stable-1-6

« back to all changes in this revision

Viewing changes to ubuntuone/storageprotocol/client.py

  • Committer: Tarmac
  • Author(s): Facundo Batista
  • Date: 2011-02-10 20:01:05 UTC
  • mfrom: (124.1.2 magic-hash)
  • Revision ID: tarmac-20110210200105-6k6wev47j7lbpm3p
The client now can send a magic hash in the PutContent request

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# Author: Lucio Torre <lucio.torre@canonical.com>
4
4
# Author: Natalia B. Bidart <natalia.bidart@canonical.com>
5
5
# Author: Guillermo Gonzalez <guillermo.gonzalez@canonical.com>
 
6
# Author: Facundo Batista <facundo@canonical.com>
6
7
#
7
8
# Copyright 2009-2011 Canonical Ltd.
8
9
#
276
277
 
277
278
    def put_content(self, share, node, previous_hash, new_hash,
278
279
                    crc32, size, deflated_size, fd, upload_id=None,
279
 
                    upload_id_cb=None):
 
280
                    upload_id_cb=None, magic_hash=None):
280
281
        """Put the content of fd into file node."""
281
282
        req = self.put_content_request(share, node, previous_hash, new_hash,
282
283
                                       crc32, size, deflated_size, fd,
283
284
                                       upload_id=upload_id,
284
 
                                       upload_id_cb=upload_id_cb)
 
285
                                       upload_id_cb=upload_id_cb,
 
286
                                       magic_hash=magic_hash)
285
287
        return req.deferred
286
288
 
287
289
    def put_content_request(self, share, node, previous_hash, new_hash,
288
290
                            crc32, size, deflated_size, fd, upload_id=None,
289
 
                            upload_id_cb=None):
 
291
                            upload_id_cb=None, magic_hash=None):
290
292
        """Put the content of fd into file node, return the request."""
291
293
        p = PutContent(self, share, node, previous_hash, new_hash,
292
294
                       crc32, size, deflated_size, fd,
293
295
                       upload_id=upload_id,
294
 
                       upload_id_cb=upload_id_cb)
 
296
                       upload_id_cb=upload_id_cb,
 
297
                       magic_hash=magic_hash)
295
298
        p.start()
296
299
        return p
297
300
 
1136
1139
    @ivar new_generation: the generation that the volume is at now
1137
1140
    """
1138
1141
 
1139
 
    def __init__(self, protocol, share, node_id,
1140
 
                 previous_hash, new_hash, crc32, size,
1141
 
                 deflated_size, fd, upload_id=None, upload_id_cb=None):
 
1142
    def __init__(self, protocol, share, node_id, previous_hash, new_hash,
 
1143
                 crc32, size, deflated_size, fd, upload_id=None,
 
1144
                 upload_id_cb=None, magic_hash=None):
1142
1145
        """Put content into a node.
1143
1146
 
1144
1147
        @param protocol: the request handler
1150
1153
        @param size: the size hint for the new content
1151
1154
        @param fd: a file-like object to read data from
1152
1155
        @param upload_id: the upload id (to resume the upload.)
 
1156
        @param upload_id_cb: callback that will be called with the upload id
 
1157
                             assigned by the server for the session
 
1158
        @param magic_hash: the magic_hash of the file
1153
1159
 
1154
1160
        """
1155
1161
        request.Request.__init__(self, protocol)
1164
1170
        self.upload_id_cb = upload_id_cb
1165
1171
        self.upload_id = upload_id
1166
1172
        self.new_generation = None
 
1173
        self.magic_hash = magic_hash
1167
1174
 
1168
1175
    def _start(self):
1169
1176
        """Send PUT_CONTENT."""
1178
1185
        message.put_content.deflated_size = self.deflated_size
1179
1186
        if self.upload_id:
1180
1187
            message.put_content.upload_id = self.upload_id
 
1188
        if self.magic_hash is not None:
 
1189
            message.put_content.magic_hash = self.magic_hash
1181
1190
        self.sendMessage(message)
1182
1191
 
1183
1192
    def processMessage(self, message):