Revision 8fe01d72

b/pithos/lib/client.py
234 234

  
235 235
    # Storage Object Services
236 236

  
237
    def retrieve_object(self, container, object, detail=False, headers=None):
237
    def retrieve_object(self, container, object, detail=False, headers=None,
238
                        version=None):
238 239
        path = '/%s/%s' % (container, object)
239 240
        format = 'json' if detail else 'text'
240
        status, headers, data = self.get(path, format, headers)
241
        params = version and {'version':version} or None 
242
        status, headers, data = self.get(path, format, headers, params)
241 243
        return data
242 244

  
243 245
    def create_object(self, container, object, f=stdin, chunked=False,
......
291 293
    def delete_object(self, container, object):
292 294
        self.delete('/%s/%s' % (container, object))
293 295

  
294
    def retrieve_object_metadata(self, container, object, restricted=False):
296
    def retrieve_object_metadata(self, container, object, restricted=False,
297
                                 version=None):
295 298
        path = '/%s/%s' % (container, object)
296 299
        prefix = restricted and 'x-object-meta-' or None
297
        return self._get_metadata(path, prefix)
300
        params = version and {'version':version} or None
301
        return self._get_metadata(path, prefix, params=params)
298 302

  
299 303
    def update_object_metadata(self, container, object, **meta):
300 304
        path = '/%s/%s' % (container, object)
b/tools/store
159 159
            self.until = int(_time.mktime(t))
160 160
        if object:
161 161
            meta = self.client.retrieve_object_metadata(container, object,
162
                                                        self.restricted)
162
                                                        self.restricted,
163
                                                        self.version)
163 164
        elif container:
164 165
            meta = self.client.retrieve_container_metadata(container,
165 166
                                                           self.restricted,
......
221 222
        parser.add_option('-f', action='store', type='str',
222 223
                          dest='file', default=None,
223 224
                          help='save output in file')
225
        parser.add_option('--version', action='store', type='str',
226
                          dest='version', default='list',
227
                          help='if \'list\' and in detailed mode get object\'s \
228
                               full version list otherwise get the specific \
229
                               version')
224 230

  
225 231
    def execute(self, path):
226 232
        headers = {}
......
233 239
            headers[a.replace('-', '_').upper()] = getattr(self, a)
234 240
        container, sep, object = path.partition('/')
235 241
        data = self.client.retrieve_object(container, object, self.detail,
236
                                          headers)
237
        if self.file:
238
            if self.detail:
239
                f = self.file and open(self.file, 'w') or stdout
240
                data = json.loads(data)
241
                print_dict(data, f=f)
242
                                          headers, self.version)
243
        f = self.file and open(self.file, 'w') or stdout
244
        if self.detail:
245
            data = json.loads(data)
246
            if self.version == 'list':
247
                print_versions(data, f=f)
242 248
            else:
243
                fw = open(self.file, 'w')
244
                fw.write(data)
245
                fw.close()
249
                print_dict(data, f=f)
246 250
        else:
247
            print data
251
            f.write(data)
252
        f.close()
248 253

  
249 254
@cli_command('put')
250 255
class PutObject(Command):
......
442 447
        else:
443 448
            f.write('%s\n' % elem)
444 449

  
450
def print_versions(data, f=stdout):
451
    if 'versions' not in data:
452
        f.write('%s\n' %data)
453
        return
454
    f.write('versions:\n')
455
    for id, t in data['versions']:
456
        f.write('%s @ %s\n' % (str(id).rjust(30), datetime.fromtimestamp(t)))
457

  
445 458
def main():
446 459
    try:
447 460
        name = argv[1]

Also available in: Unified diff