Revision 2db16f05 tools/lib/transfer.py
b/tools/lib/transfer.py | ||
---|---|---|
40 | 40 |
from client import Fault |
41 | 41 |
|
42 | 42 |
|
43 |
def upload(client, file, container, prefix, name=None): |
|
43 |
def upload(client, file, container, prefix, name=None, mimetype=None):
|
|
44 | 44 |
|
45 | 45 |
meta = client.retrieve_container_metadata(container) |
46 | 46 |
blocksize = int(meta['x-container-block-size']) |
... | ... | |
48 | 48 |
|
49 | 49 |
size = os.path.getsize(file) |
50 | 50 |
hashes = HashMap(blocksize, blockhash) |
51 |
hashes.load(file)
|
|
51 |
hashes.load(open(file))
|
|
52 | 52 |
map = {'bytes': size, 'hashes': [hexlify(x) for x in hashes]} |
53 | 53 |
|
54 | 54 |
objectname = name if name else os.path.split(file)[-1] |
55 | 55 |
object = prefix + objectname |
56 |
kwargs = {'mimetype':mimetype} if mimetype else {} |
|
57 |
v = None |
|
56 | 58 |
try: |
57 |
client.create_object_by_hashmap(container, object, map)
|
|
59 |
v = client.create_object_by_hashmap(container, object, map, **kwargs)
|
|
58 | 60 |
except Fault, fault: |
59 | 61 |
if fault.status != 409: |
60 | 62 |
raise |
61 | 63 |
else: |
62 |
return |
|
64 |
return v
|
|
63 | 65 |
|
64 | 66 |
if type(fault.data) == types.StringType: |
65 | 67 |
missing = fault.data.split('\n') |
... | ... | |
76 | 78 |
block = fp.read(blocksize) |
77 | 79 |
client.update_container_data(container, StringIO(block)) |
78 | 80 |
|
79 |
client.create_object_by_hashmap(container, object, map)
|
|
81 |
return client.create_object_by_hashmap(container, object, map, **kwargs)
|
|
80 | 82 |
|
81 | 83 |
def download(client, container, object, file): |
82 | 84 |
|
Also available in: Unified diff