48 |
48 |
CLISyntaxError)
|
49 |
49 |
from kamaki.cli.argument import (
|
50 |
50 |
FlagArgument, IntArgument, ValueArgument, DateArgument, KeyValueArgument,
|
51 |
|
ProgressBarArgument, RepeatableArgument, DataSizeArgument)
|
|
51 |
ProgressBarArgument, RepeatableArgument, DataSizeArgument,
|
|
52 |
UserAccountArgument)
|
52 |
53 |
from kamaki.cli.utils import (
|
53 |
54 |
format_size, bold, get_path_size, guess_mime_type)
|
54 |
55 |
|
... | ... | |
119 |
120 |
|
120 |
121 |
def __init__(self, arguments={}, auth_base=None, cloud=None):
|
121 |
122 |
super(_pithos_account, self).__init__(arguments, auth_base, cloud)
|
122 |
|
self['account'] = ValueArgument(
|
123 |
|
'Use (a different) user uuid', ('-A', '--account'))
|
|
123 |
self['account'] = UserAccountArgument(
|
|
124 |
'A user UUID or name', ('-A', '--account'))
|
|
125 |
self.arguments['account'].account_client = auth_base
|
124 |
126 |
|
125 |
127 |
def print_objects(self, object_list):
|
126 |
128 |
for index, obj in enumerate(object_list):
|
... | ... | |
329 |
331 |
"""Modify the attributes of a file or directory object"""
|
330 |
332 |
|
331 |
333 |
arguments = dict(
|
332 |
|
publish=FlagArgument(
|
333 |
|
'Make an object public (returns the public URL)', '--publish'),
|
334 |
|
unpublish=FlagArgument(
|
335 |
|
'Make an object unpublic', '--unpublish'),
|
336 |
334 |
uuid_for_read_permission=RepeatableArgument(
|
337 |
335 |
'Give read access to user/group (can be repeated, accumulative). '
|
338 |
336 |
'Format for users: UUID . Format for groups: UUID:GROUP . '
|
... | ... | |
349 |
347 |
'Delete object metadata (can be repeated)', '--metadata-del'),
|
350 |
348 |
)
|
351 |
349 |
required = [
|
352 |
|
'publish', 'unpublish', 'uuid_for_read_permission', 'metadata_to_set',
|
|
350 |
'uuid_for_read_permission', 'metadata_to_set',
|
353 |
351 |
'uuid_for_write_permission', 'no_permissions',
|
354 |
352 |
'metadata_key_to_delete']
|
355 |
353 |
|
... | ... | |
358 |
356 |
@errors.pithos.container
|
359 |
357 |
@errors.pithos.object_path
|
360 |
358 |
def _run(self):
|
361 |
|
if self['publish']:
|
362 |
|
self.writeln(self.client.publish_object(self.path))
|
363 |
|
if self['unpublish']:
|
364 |
|
self.client.unpublish_object(self.path)
|
365 |
359 |
if self['uuid_for_read_permission'] or self[
|
366 |
360 |
'uuid_for_write_permission']:
|
367 |
361 |
perms = self.client.get_object_sharing(self.path)
|
... | ... | |
398 |
392 |
self._run()
|
399 |
393 |
|
400 |
394 |
|
|
395 |
@command(file_cmds)
|
|
396 |
class file_publish(_pithos_container):
|
|
397 |
"""Publish an object (creates a public URL)"""
|
|
398 |
|
|
399 |
@errors.generic.all
|
|
400 |
@errors.pithos.connection
|
|
401 |
@errors.pithos.container
|
|
402 |
@errors.pithos.object_path
|
|
403 |
def _run(self):
|
|
404 |
self.writeln(self.client.publish_object(self.path))
|
|
405 |
|
|
406 |
def main(self, path_or_url):
|
|
407 |
super(self.__class__, self)._run(path_or_url)
|
|
408 |
self._run()
|
|
409 |
|
|
410 |
|
|
411 |
@command(file_cmds)
|
|
412 |
class file_unpublish(_pithos_container):
|
|
413 |
"""Unpublish an object"""
|
|
414 |
|
|
415 |
@errors.generic.all
|
|
416 |
@errors.pithos.connection
|
|
417 |
@errors.pithos.container
|
|
418 |
@errors.pithos.object_path
|
|
419 |
def _run(self):
|
|
420 |
self.client.unpublish_object(self.path)
|
|
421 |
|
|
422 |
def main(self, path_or_url):
|
|
423 |
super(self.__class__, self)._run(path_or_url)
|
|
424 |
self._run()
|
|
425 |
|
|
426 |
|
401 |
427 |
def _assert_path(self, path_or_url):
|
402 |
428 |
if not self.path:
|
403 |
429 |
raiseCLIError(
|
... | ... | |
488 |
514 |
class _source_destination(_pithos_container, _optional_output_cmd):
|
489 |
515 |
|
490 |
516 |
sd_arguments = dict(
|
491 |
|
destination_user_uuid=ValueArgument(
|
492 |
|
'default: current user uuid', '--to-account'),
|
|
517 |
destination_user=UserAccountArgument(
|
|
518 |
'UUID or username, default: current user', '--to-account'),
|
493 |
519 |
destination_container=ValueArgument(
|
494 |
520 |
'default: pithos', '--to-container'),
|
495 |
521 |
source_prefix=FlagArgument(
|
... | ... | |
508 |
534 |
self.arguments.update(self.sd_arguments)
|
509 |
535 |
super(_source_destination, self).__init__(
|
510 |
536 |
self.arguments, auth_base, cloud)
|
|
537 |
self.arguments['destination_user'].account_client = self.auth_base
|
511 |
538 |
|
512 |
539 |
def _report_transfer(self, src, dst, transfer_name):
|
513 |
540 |
if not dst:
|
... | ... | |
636 |
663 |
base_url=self.client.base_url, token=self.client.token,
|
637 |
664 |
container=self[
|
638 |
665 |
'destination_container'] or dst_con or self.client.container,
|
639 |
|
account=self[
|
640 |
|
'destination_user_uuid'] or dst_acc or self.account)
|
|
666 |
account=self['destination_user'] or dst_acc or self.account)
|
641 |
667 |
self.dst_path = dst_path or self.path
|
642 |
668 |
|
643 |
669 |
|
... | ... | |
1640 |
1666 |
def _run(self):
|
1641 |
1667 |
self._print(self.client.get_account_info(), self.print_dict)
|
1642 |
1668 |
|
1643 |
|
def main(self, account_uuid=None):
|
|
1669 |
def main(self, account_uuid_or_name=None):
|
1644 |
1670 |
super(self.__class__, self)._run()
|
1645 |
|
if account_uuid:
|
1646 |
|
self.client.account, self.account = account_uuid, account_uuid
|
|
1671 |
if account_uuid_or_name:
|
|
1672 |
arg = UserAccountArgument('Check', ' ')
|
|
1673 |
arg.account_client = self.auth_base
|
|
1674 |
arg.value = account_uuid_or_name
|
|
1675 |
self.client.account, self.account = arg.value, arg.value
|
1647 |
1676 |
self._run()
|
1648 |
1677 |
|
1649 |
1678 |
|
... | ... | |
1721 |
1750 |
def main(self, groupname):
|
1722 |
1751 |
super(self.__class__, self)._run()
|
1723 |
1752 |
self._run(groupname)
|
1724 |
|
|
1725 |
|
|
1726 |
|
# Deprecated commands
|
1727 |
|
|
1728 |
|
@command(file_cmds)
|
1729 |
|
class file_publish(_pithos_init):
|
1730 |
|
"""DEPRECATED, replaced by [kamaki] file modify OBJECT --publish"""
|
1731 |
|
|
1732 |
|
def main(self, *args):
|
1733 |
|
raise CLISyntaxError('DEPRECATED', details=[
|
1734 |
|
'This command is replaced by:',
|
1735 |
|
' [kamaki] file modify OBJECT --publish'])
|
1736 |
|
|
1737 |
|
|
1738 |
|
@command(file_cmds)
|
1739 |
|
class file_unpublish(_pithos_init):
|
1740 |
|
"""DEPRECATED, replaced by [kamaki] file modify OBJECT --unpublish"""
|
1741 |
|
|
1742 |
|
def main(self, *args):
|
1743 |
|
raise CLISyntaxError('DEPRECATED', details=[
|
1744 |
|
'This command is replaced by:',
|
1745 |
|
' [kamaki] file modify OBJECT --unpublish'])
|