Revision 1e29b9f6 kamaki/cli/commands/pithos_cli.py

b/kamaki/cli/commands/pithos_cli.py
41 41
from kamaki.cli.commands import _command_init
42 42
from kamaki.clients.pithos import PithosClient, ClientError
43 43
from kamaki.cli.utils import bold
44
from sys import stdout, stdin
44
from sys import stdout
45 45
from time import localtime, strftime
46 46
from logging import getLogger
47 47

  
......
51 51
_commands = [pithos_cmds]
52 52

  
53 53

  
54
about_directories = [
55
    'Kamaki hanldes directories the same way as OOS Storage and Pithos+:',
56
    'A directory is an object with type "application/directory"',
57
    'An object with path dir/name can exist even if dir does not exist or',
58
    'even if dir is a non directory object. Users can modify dir without',
59
    'affecting the dir/name object in any way.']
60

  
61

  
54 62
# Argument functionality
55 63

  
56 64

  
......
380 388

  
381 389
@command(pithos_cmds)
382 390
class store_mkdir(_store_container_command):
383
    """Create a directory"""
391
    """Create a directory
392
    """
393

  
394
    __doc__ += '\n. '.join(about_directories)
384 395

  
385 396
    def main(self, container___directory):
386 397
        super(self.__class__,
......
388 399
        try:
389 400
            self.client.create_directory(self.path)
390 401
        except ClientError as err:
402
            if err.status == 404:
403
                if 'container' in ('%s' % err).lower():
404
                    raiseCLIError(
405
                        err,
406
                        'No container %s in account %s'\
407
                        % (self.container, self.account),
408
                        details=self.generic_err_details)
409
            raiseCLIError(err)
410
        except Exception as err:
391 411
            raiseCLIError(err)
392 412

  
393 413

  
394 414
@command(pithos_cmds)
395
class store_create(_store_container_command):
396
    """Create a container or a directory object"""
415
class store_touch(_store_container_command):
416
    """Create an empty object (file)
417
    If object exists, this command will reset it to 0 length
418
    """
419

  
420
    arguments = dict(
421
        content_type=ValueArgument(
422
            'Set content type (default: application/octet-stream)',
423
            '--content-type',
424
            default='application/octet-stream')
425
    )
426

  
427
    def main(self, container___path):
428
        super(store_touch, self).main(container___path)
429
        try:
430
            self.client.create_object(self.path, self['content_type'])
431
        except ClientError as err:
432
            if err.status == 404:
433
                if 'container' in ('%s' % err).lower():
434
                    raiseCLIError(
435
                        err,
436
                        'No container %s in account %s'\
437
                        % (self.container, self.account),
438
                        details=self.generic_err_details)
439
            raiseCLIError(err)
440
        except Exception as err:
441
            raiseCLIError(err)
442

  
443

  
444
@command(pithos_cmds)
445
class store_create(_store_account_command):
446
    """Create a container"""
397 447

  
398 448
    arguments = dict(
399 449
        versioning=ValueArgument(
......
405 455
            '--meta')
406 456
    )
407 457

  
408
    def main(self, container____directory__):
409
        super(self.__class__, self).main(container____directory__)
458
    def main(self, container):
459
        super(self.__class__, self).main(container)
410 460
        try:
411
            if self.path is None:
412
                self.client.container_put(quota=self['quota'],
413
                    versioning=self['versioning'],
414
                    metadata=self['meta'])
415
            else:
416
                self.client.create_directory(self.path)
461
            self.client.container_put(quota=self['quota'],
462
                versioning=self['versioning'],
463
                metadata=self['meta'])
417 464
        except ClientError as err:
465
            if err.status == 404:
466
                if 'container' in ('%s' % err).lower():
467
                    raiseCLIError(
468
                        err,
469
                        'No container %s in account %s'\
470
                        % (self.container, self.account),
471
                        details=self.generic_err_details)
418 472
            raiseCLIError(err)
473
        except Exception as e:
474
            raiseCLIError(e)
419 475

  
420 476

  
421 477
@command(pithos_cmds)
......
445 501

  
446 502
    def __init__(self, arguments={}):
447 503
        super(self.__class__, self).__init__(arguments)
448
        self['delimiter']=DelimiterArgument(
504
        self['delimiter'] = DelimiterArgument(
449 505
            self,
450 506
            parsed_name='--delimiter',
451 507
            help=u'copy objects prefixed as src_object + delimiter')
......
1250 1306
            print('\t%s \t(%s)' % (vid, strftime('%d-%m-%Y %H:%M:%S', t)))
1251 1307

  
1252 1308

  
1253
@command(pithos_cmds)
1254
class store_touch(_store_container_command):
1255
    """Create an empty file
1256
    If object exists, this command will reset it to 0 length
1257
    """
1258

  
1259
    arguments = dict(
1260
        content_type=ValueArgument(
1261
            'Set content type (default: application/octet-stream)',
1262
            '--content-type',
1263
            default='application/octet-stream')
1264
    )
1265

  
1266
    def main(self, container___path):
1267
        super(store_touch, self).main(container___path)
1268
        try:
1269
            self.client.create_object(self.path, self['content_type'])
1270
        except ClientError as err:
1271
            raiseCLIError(err)

Also available in: Unified diff