Revision 8fe01d72 tools/store

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