Revision 38a79780
b/kamaki/clients/pithos/__init__.py | ||
---|---|---|
1384 | 1384 |
|
1385 | 1385 |
def overwrite_object( |
1386 | 1386 |
self, obj, start, end, source_file, |
1387 |
content_type=None, upload_cb=None):
|
|
1387 |
upload_cb=None): |
|
1388 | 1388 |
"""Overwrite a part of an object from local source file |
1389 |
ATTENTION: content_type must always be application/octet-stream |
|
1389 | 1390 |
|
1390 | 1391 |
:param obj: (str) remote object path |
1391 | 1392 |
|
... | ... | |
1395 | 1396 |
|
1396 | 1397 |
:param source_file: open file descriptor |
1397 | 1398 |
|
1398 |
:param content_type: (str) default: application/octet-stream |
|
1399 |
|
|
1400 | 1399 |
:param upload_db: progress.bar for uploading |
1401 | 1400 |
""" |
1402 | 1401 |
|
1402 |
self._assert_container() |
|
1403 | 1403 |
r = self.get_object_info(obj) |
1404 | 1404 |
rf_size = int(r['content-length']) |
1405 |
if rf_size < int(start): |
|
1406 |
raise ClientError( |
|
1407 |
'Range start exceeds file size', |
|
1408 |
status=416) |
|
1409 |
elif rf_size < int(end): |
|
1410 |
raise ClientError( |
|
1411 |
'Range end exceeds file size', |
|
1412 |
status=416) |
|
1413 |
self._assert_container() |
|
1405 |
start, end = int(start), int(end) |
|
1406 |
assert rf_size >= start, 'Range start %s exceeds file size %s' % ( |
|
1407 |
start, rf_size) |
|
1414 | 1408 |
meta = self.get_container_info() |
1415 | 1409 |
blocksize = int(meta['x-container-block-size']) |
1416 | 1410 |
filesize = fstat(source_file.fileno()).st_size |
1417 |
datasize = int(end) - int(start) + 1
|
|
1411 |
datasize = end - start + 1
|
|
1418 | 1412 |
nblocks = 1 + (datasize - 1) // blocksize |
1419 | 1413 |
offset = 0 |
1420 | 1414 |
if upload_cb: |
... | ... | |
1427 | 1421 |
r = self.object_post( |
1428 | 1422 |
obj, |
1429 | 1423 |
update=True, |
1430 |
content_type=content_type or 'application/octet-stream',
|
|
1424 |
content_type='application/octet-stream', |
|
1431 | 1425 |
content_length=len(block), |
1432 | 1426 |
content_range='bytes %s-%s/*' % ( |
1433 | 1427 |
start + offset, |
Also available in: Unified diff