Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-app / pithos / api / management / commands / file-show.py @ c598a8a7

History | View | Annotate | Download (3.8 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
42

    
43

    
44
class Command(SynnefoCommand):
45
    args = "<account> <container> <object>"
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
    )
56

    
57
    def handle(self, *args, **options):
58
        if len(args) != 3:
59
            raise CommandError("Invalid number of arguments")
60

    
61
        success_status = False
62
        try:
63
            b = get_backend()
64
            b.pre_exec()
65

    
66
            account, container, name = args
67

    
68
            kv = b.get_object_meta(account, account, container, name,
69
                                   options['domain'], options['obj_version'])
70

    
71
            if options['obj_version'] is None:
72
                _, path, permissions = b.get_object_permissions(account,
73
                                                                account,
74
                                                                container,
75
                                                                name)
76
                if path is not None:
77
                    kv['permissions'] = path, dict(permissions)
78

    
79
                public = b.get_object_public(account, account, container, name)
80
                if public is not None:
81
                    update_public_meta(public, kv)
82

    
83
            kv['hashmap'] = b.get_object_hashmap(account, account, container,
84
                                                 name,
85
                                                 options['obj_version'])[-1]
86

    
87
            utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
88
                               options["output_format"], vertical=True)
89

    
90
            success_status = True
91
        except Exception, e:
92
            raise CommandError(e)
93
        finally:
94
            b.post_exec(success_status)
95
            b.close()