root / snf-pithos-app / pithos / api / management / commands / file-show.py @ 91fc9266
History | View | Annotate | Download (4.4 kB)
1 |
# Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
from django.core.management.base import CommandError |
35 |
|
36 |
from optparse import make_option |
37 |
|
38 |
from snf_django.management.commands import SynnefoCommand |
39 |
from snf_django.management import utils |
40 |
|
41 |
from pithos.api.util import get_backend, update_public_meta, is_uuid |
42 |
|
43 |
|
44 |
class Command(SynnefoCommand): |
45 |
args = "<account> <container> <object> or <object uuid>"
|
46 |
help = """Show file information"""
|
47 |
|
48 |
option_list = SynnefoCommand.option_list + ( |
49 |
make_option("--obj-version", dest="obj_version", |
50 |
default=None,
|
51 |
help="Show information for a specific file version"),
|
52 |
make_option("--domain", dest="domain", |
53 |
default='pithos',
|
54 |
help="Show file attributes from the specific domain."),
|
55 |
make_option("--hashmap", dest="hashmap", |
56 |
default=False,
|
57 |
action='store_true',
|
58 |
help="Display also the object hashmap")
|
59 |
) |
60 |
|
61 |
def handle(self, *args, **options): |
62 |
success_status = False
|
63 |
try:
|
64 |
b = get_backend() |
65 |
b.pre_exec() |
66 |
|
67 |
if len(args) == 3: |
68 |
account, container, name = args |
69 |
elif len(args) == 1: |
70 |
if not is_uuid(args[0]): |
71 |
raise CommandError('Invalid UUID') |
72 |
try:
|
73 |
account, container, name = b.get_uuid( |
74 |
None, args[0], check_permissions=False) |
75 |
except NameError: |
76 |
raise CommandError('Unknown UUID') |
77 |
else:
|
78 |
raise CommandError("Invalid number of arguments") |
79 |
|
80 |
kv = b.get_object_meta(account, account, container, name, |
81 |
options['domain'], options['obj_version']) |
82 |
|
83 |
if options['obj_version'] is None: |
84 |
_, path, permissions = b.get_object_permissions(account, |
85 |
account, |
86 |
container, |
87 |
name) |
88 |
if path is not None: |
89 |
kv['permissions'] = path, dict(permissions) |
90 |
|
91 |
public = b.get_object_public(account, account, container, name) |
92 |
if public is not None: |
93 |
update_public_meta(public, kv) |
94 |
|
95 |
if options['hashmap']: |
96 |
_, kv['hashmap'] = b.get_object_hashmap(account, account,
|
97 |
container, name, |
98 |
options['obj_version'])
|
99 |
|
100 |
utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
|
101 |
options["output_format"], vertical=True) |
102 |
|
103 |
success_status = True
|
104 |
except Exception, e: |
105 |
raise CommandError(e)
|
106 |
finally:
|
107 |
b.post_exec(success_status) |
108 |
b.close() |