Revision 0c6d7489

b/kamaki/clients/pithos.py
1
# Copyright 2011 GRNET S.A. All rights reserved.
1
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2 2
#
3 3
# Redistribution and use in source and binary forms, with or
4 4
# without modification, are permitted provided that the following
......
36 36

  
37 37
from time import time
38 38

  
39
from ..utils import OrderedDict
40

  
41 39
from .storage import StorageClient
42 40

  
43 41

  
......
85 83
        
86 84
        file_size = size if size is not None else os.fstat(f.fileno()).st_size
87 85
        nblocks = 1 + (file_size - 1) // blocksize
88
        hashes = OrderedDict()
89
        
86
        hashes = []
87
        map = {}
88

  
90 89
        size = 0
91 90
        
92 91
        if hash_cb:
93 92
            hash_gen = hash_cb(nblocks)
94 93
            hash_gen.next()
94
    
95 95
        for i in range(nblocks):
96 96
            block = f.read(blocksize)
97 97
            bytes = len(block)
98 98
            hash = pithos_hash(block, blockhash)
99
            hashes[hash] = (size, bytes)
99
            hashes.append(hash)
100
            map[hash] = (size, bytes)
100 101
            size += bytes
101 102
            if hash_cb:
102 103
                hash_gen.next()
......
105 106
                
106 107
        path = '/%s/%s/%s' % (self.account, self.container, object)
107 108
        params = dict(format='json', hashmap='')
108
        hashmap = dict(bytes=size, hashes=hashes.keys())
109
        hashmap = dict(bytes=size, hashes=hashes)
109 110
        r = self.put(path, params=params, json=hashmap, success=(201, 409))
110 111
        
111 112
        if r.status_code == 201:
......
116 117
        if upload_cb:
117 118
            upload_gen = upload_cb(len(missing))
118 119
            upload_gen.next()
120

  
119 121
        for hash in missing:
120
            offset, bytes = hashes[hash]
122
            offset, bytes = map[hash]
121 123
            f.seek(offset)
122 124
            data = f.read(bytes)
123 125
            self.put_block(data, hash)
124 126
            if upload_cb:
125 127
                upload_gen.next()
126
        
128

  
127 129
        self.put(path, params=params, json=hashmap, success=201)

Also available in: Unified diff