Revision f7ab99df tools/store

b/tools/store
57 57
        
58 58
        self.parser = parser
59 59
        self.args = args
60

  
60
        
61 61
    def add_options(self, parser):
62 62
        pass
63

  
63
    
64 64
    def execute(self, *args):
65 65
        pass
66 66

  
......
99 99
                          default=False, help='show metadata until that date')
100 100
        parser.add_option('--format', action='store', dest='format',
101 101
                          default='%d/%m/%Y', help='format to parse until date')
102

  
102
    
103 103
    def execute(self, container=None):
104 104
        if container:
105 105
            self.list_objects(container)
106 106
        else:
107 107
            self.list_containers()
108

  
108
    
109 109
    def list_containers(self):
110 110
        params = {'limit':self.limit, 'marker':self.marker}
111 111
        headers = {'IF_MODIFIED_SINCE':self.if_modified_since,
......
117 117
        
118 118
        l = self.client.list_containers(self.detail, params, headers)
119 119
        print_list(l)
120

  
120
    
121 121
    def list_objects(self, container):
122 122
        params = {'limit':self.limit, 'marker':self.marker,
123 123
                  'prefix':self.prefix, 'delimiter':self.delimiter,
......
150 150
        parser.add_option('--version', action='store', dest='version',
151 151
                          default=None, help='show specific version \
152 152
                                  (applies only for objects)')
153

  
153
    
154 154
    def execute(self, path=''):
155 155
        container, sep, object = path.partition('/')
156 156
        if self.until:
......
228 228
        parser.add_option('--versionlist', action='store_true',
229 229
                          dest='versionlist', default=False,
230 230
                          help='get the full object version list')
231

  
231
    
232 232
    def execute(self, path):
233 233
        headers = {}
234 234
        if self.range:
......
255 255
            f.write(data)
256 256
        f.close()
257 257

  
258
@cli_command('mkdir')
259
class PutMarker(Command):
260
    syntax = '<container>/<directory marker>'
261
    description = 'create a directory marker'
262
    
263
    def execute(self, path):
264
        container, sep, object = path.partition('/')
265
        self.client.create_directory_marker(container, object)
266

  
258 267
@cli_command('put')
259 268
class PutObject(Command):
260 269
    syntax = '<container>/<object> <path> [key=val] [...]'
261 270
    description = 'create/override object with path contents or standard input'
262

  
271
    
263 272
    def add_options(self, parser):
264 273
        parser.add_option('--chunked', action='store_true', dest='chunked',
265 274
                          default=False, help='set chunked transfer mode')
......
274 283
        parser.add_option('--manifest', action='store', type='str',
275 284
                          dest='manifest', default=None,
276 285
                          help='use for large file support')
286
        parser.add_option('--type', action='store',
287
                          dest='content-type', default=False,
288
                          help='create object with specific content type')
277 289
        parser.add_option('--touch', action='store_true',
278 290
                          dest='touch', default=False,
279 291
                          help='create object with zero data')
280

  
292
    
281 293
    def execute(self, path, srcpath='-', *args):
282 294
        headers = {}
283 295
        if self.manifest:
284 296
            headers['X_OBJECT_MANIFEST'] = self.manifest
285 297
            
286 298
        attrs = ['etag', 'content-encoding', 'content-disposition']
299
        
300
        attrs = ['etag', 'content-encoding', 'content-disposition',
301
                 'content-type']
287 302
        attrs = [a for a in attrs if getattr(self, a)]
288 303
        for a in attrs:
289 304
            headers[a.replace('-', '_').upper()] = getattr(self, a)
......
314 329
        parser.add_option('--version', action='store',
315 330
                          dest='version', default=False,
316 331
                          help='copy specific version')
317

  
332
    
318 333
    def execute(self, src, dst):
319 334
        src_container, sep, src_object = src.partition('/')
320 335
        dst_container, sep, dst_object = dst.partition('/')
......
376 391
        parser.add_option('--manifest', action='store', type='str',
377 392
                          dest='manifest', default=None,
378 393
                          help='use for large file support')
379

  
394
    
380 395
    def execute(self, path, srcpath='-', *args):
381 396
        headers = {}
382 397
        if self.manifest:
......
429 444
        self.client.move_object(src_container, src_object, dst_container,
430 445
                                dst_object, headers)
431 446

  
447
@cli_command('remove', 'rm')
448
class TrashObject(Command):
449
    syntax = '<container>/<object>'
450
    description = 'trashes an object'
451
    
452
    def execute(self, src):
453
        src_container, sep, src_object = src.partition('/')
454
        
455
        self.client.trash_object(src_container, src_object)
456

  
457
@cli_command('restore')
458
class TrashObject(Command):
459
    syntax = '<container>/<object>'
460
    description = 'trashes an object'
461
    
462
    def execute(self, src):
463
        src_container, sep, src_object = src.partition('/')
464
        
465
        self.client.restore_object(src_container, src_object)
466

  
467
@cli_command('unset')
468
class TrashObject(Command):
469
    syntax = '<container>/[<object>] key [key] [...]'
470
    description = 'deletes metadata info'
471
    
472
    def execute(self, path, *args):
473
        #in case of account fix the args
474
        if path.find('=') != -1:
475
            args = list(args)
476
            args.append(path)
477
            args = tuple(args)
478
            path = ''
479
        meta = []
480
        for key in args:
481
            meta.append(key)
482
        container, sep, object = path.partition('/')
483
        if object:
484
            self.client.delete_object_metadata(container, object, meta)
485
        elif container:
486
            self.client.delete_container_metadata(container, meta)
487
        else:
488
            self.client.delete_account_metadata(meta)
489

  
432 490
def print_usage():
433 491
    cmd = Command([])
434 492
    parser = cmd.parser
......
497 555
        exit(1)
498 556
    except Fault, f:
499 557
        print f.status, f.data
558
        status = f.status and '%s ' % f.status or ''
559
        print '%s%s' % (status, f.data)
500 560

  
501 561
if __name__ == '__main__':
502 562
    main()

Also available in: Unified diff