CLISyntaxError)
from kamaki.cli.argument import (
FlagArgument, IntArgument, ValueArgument, DateArgument, KeyValueArgument,
- ProgressBarArgument, RepeatableArgument, DataSizeArgument)
+ ProgressBarArgument, RepeatableArgument, DataSizeArgument,
+ UserAccountArgument)
from kamaki.cli.utils import (
format_size, bold, get_path_size, guess_mime_type)
def __init__(self, arguments={}, auth_base=None, cloud=None):
super(_pithos_account, self).__init__(arguments, auth_base, cloud)
- self['account'] = ValueArgument(
- 'Use (a different) user uuid', ('-A', '--account'))
+ self['account'] = UserAccountArgument(
+ 'A user UUID or name', ('-A', '--account'))
+ self.arguments['account'].account_client = auth_base
def print_objects(self, object_list):
for index, obj in enumerate(object_list):
"""Modify the attributes of a file or directory object"""
arguments = dict(
- publish=FlagArgument(
- 'Make an object public (returns the public URL)', '--publish'),
- unpublish=FlagArgument(
- 'Make an object unpublic', '--unpublish'),
uuid_for_read_permission=RepeatableArgument(
'Give read access to user/group (can be repeated, accumulative). '
'Format for users: UUID . Format for groups: UUID:GROUP . '
'Delete object metadata (can be repeated)', '--metadata-del'),
)
required = [
- 'publish', 'unpublish', 'uuid_for_read_permission', 'metadata_to_set',
+ 'uuid_for_read_permission', 'metadata_to_set',
'uuid_for_write_permission', 'no_permissions',
'metadata_key_to_delete']
@errors.pithos.container
@errors.pithos.object_path
def _run(self):
- if self['publish']:
- self.writeln(self.client.publish_object(self.path))
- if self['unpublish']:
- self.client.unpublish_object(self.path)
if self['uuid_for_read_permission'] or self[
'uuid_for_write_permission']:
perms = self.client.get_object_sharing(self.path)
self._run()
+@command(file_cmds)
+class file_publish(_pithos_container):
+ """Publish an object (creates a public URL)"""
+
+ @errors.generic.all
+ @errors.pithos.connection
+ @errors.pithos.container
+ @errors.pithos.object_path
+ def _run(self):
+ self.writeln(self.client.publish_object(self.path))
+
+ def main(self, path_or_url):
+ super(self.__class__, self)._run(path_or_url)
+ self._run()
+
+
+@command(file_cmds)
+class file_unpublish(_pithos_container):
+ """Unpublish an object"""
+
+ @errors.generic.all
+ @errors.pithos.connection
+ @errors.pithos.container
+ @errors.pithos.object_path
+ def _run(self):
+ self.client.unpublish_object(self.path)
+
+ def main(self, path_or_url):
+ super(self.__class__, self)._run(path_or_url)
+ self._run()
+
+
def _assert_path(self, path_or_url):
if not self.path:
raiseCLIError(
class _source_destination(_pithos_container, _optional_output_cmd):
sd_arguments = dict(
- destination_user_uuid=ValueArgument(
- 'default: current user uuid', '--to-account'),
+ destination_user=UserAccountArgument(
+ 'UUID or username, default: current user', '--to-account'),
destination_container=ValueArgument(
'default: pithos', '--to-container'),
source_prefix=FlagArgument(
self.arguments.update(self.sd_arguments)
super(_source_destination, self).__init__(
self.arguments, auth_base, cloud)
+ self.arguments['destination_user'].account_client = self.auth_base
def _report_transfer(self, src, dst, transfer_name):
if not dst:
base_url=self.client.base_url, token=self.client.token,
container=self[
'destination_container'] or dst_con or self.client.container,
- account=self[
- 'destination_user_uuid'] or dst_acc or self.account)
+ account=self['destination_user'] or dst_acc or self.account)
self.dst_path = dst_path or self.path
def _run(self):
self._print(self.client.get_account_info(), self.print_dict)
- def main(self, account_uuid=None):
+ def main(self, account_uuid_or_name=None):
super(self.__class__, self)._run()
- if account_uuid:
- self.client.account, self.account = account_uuid, account_uuid
+ if account_uuid_or_name:
+ arg = UserAccountArgument('Check', ' ')
+ arg.account_client = self.auth_base
+ arg.value = account_uuid_or_name
+ self.client.account, self.account = arg.value, arg.value
self._run()
def main(self, groupname):
super(self.__class__, self)._run()
self._run(groupname)
-
-
-# Deprecated commands
-
-@command(file_cmds)
-class file_publish(_pithos_init):
- """DEPRECATED, replaced by [kamaki] file modify OBJECT --publish"""
-
- def main(self, *args):
- raise CLISyntaxError('DEPRECATED', details=[
- 'This command is replaced by:',
- ' [kamaki] file modify OBJECT --publish'])
-
-
-@command(file_cmds)
-class file_unpublish(_pithos_init):
- """DEPRECATED, replaced by [kamaki] file modify OBJECT --unpublish"""
-
- def main(self, *args):
- raise CLISyntaxError('DEPRECATED', details=[
- 'This command is replaced by:',
- ' [kamaki] file modify OBJECT --unpublish'])