Commit bb55355a authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

pithos: Slight modifications in file-show command

* Search by object UUID
* Do not display hashmap by default
parent 1c6539da
......@@ -38,11 +38,11 @@ from optparse import make_option
from snf_django.management.commands import SynnefoCommand
from snf_django.management import utils
from pithos.api.util import get_backend, update_public_meta
from pithos.api.util import get_backend, update_public_meta, is_uuid
class Command(SynnefoCommand):
args = "<account> <container> <object>"
args = "<account> <container> <object> or <object uuid>"
help = """Show file information"""
option_list = SynnefoCommand.option_list + (
......@@ -52,18 +52,30 @@ class Command(SynnefoCommand):
make_option("--domain", dest="domain",
default='pithos',
help="Show file attributes from the specific domain."),
make_option("--hashmap", dest="hashmap",
default=False,
action='store_true',
help="Display also the object hashmap")
)
def handle(self, *args, **options):
if len(args) != 3:
raise CommandError("Invalid number of arguments")
success_status = False
try:
b = get_backend()
b.pre_exec()
account, container, name = args
if len(args) == 3:
account, container, name = args
elif len(args) == 1:
if not is_uuid(args[0]):
raise CommandError('Invalid UUID')
try:
account, container, name = b.get_uuid(
None, args[0], check_permissions=False)
except NameError:
raise CommandError('Unknown UUID')
else:
raise CommandError("Invalid number of arguments")
kv = b.get_object_meta(account, account, container, name,
options['domain'], options['obj_version'])
......@@ -80,9 +92,10 @@ class Command(SynnefoCommand):
if public is not None:
update_public_meta(public, kv)
kv['hashmap'] = b.get_object_hashmap(account, account, container,
name,
options['obj_version'])[-1]
if options['hashmap']:
_, kv['hashmap'] = b.get_object_hashmap(account, account,
container, name,
options['obj_version'])
utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
options["output_format"], vertical=True)
......
......@@ -1367,7 +1367,7 @@ class ModularBackend(BaseBackend):
@debug_method
@backend_method
def get_uuid(self, user, uuid):
def get_uuid(self, user, uuid, check_permissions=True):
"""Return the (account, container, name) for the UUID given."""
info = self.node.latest_uuid(uuid, CLUSTER_NORMAL)
......@@ -1375,7 +1375,8 @@ class ModularBackend(BaseBackend):
raise NameError
path, serial = info
account, container, name = path.split('/', 2)
self._can_read(user, account, container, name)
if check_permissions:
self._can_read(user, account, container, name)
return (account, container, name)
@debug_method
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment