Statistics
| Branch: | Tag: | Revision:

root / kamaki / cli / commands / __init__.py @ e15d78e2

History | View | Annotate | Download (3.2 kB)

1 5eae854d Stavros Sachtouris
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2 5eae854d Stavros Sachtouris
#
3 5eae854d Stavros Sachtouris
# Redistribution and use in source and binary forms, with or
4 5eae854d Stavros Sachtouris
# without modification, are permitted provided that the following
5 5eae854d Stavros Sachtouris
# conditions are met:
6 5eae854d Stavros Sachtouris
#
7 5eae854d Stavros Sachtouris
#   1. Redistributions of source code must retain the above
8 5eae854d Stavros Sachtouris
#      copyright notice, this list of conditions and the following
9 5eae854d Stavros Sachtouris
#      disclaimer.
10 5eae854d Stavros Sachtouris
#
11 5eae854d Stavros Sachtouris
#   2. Redistributions in binary form must reproduce the above
12 5eae854d Stavros Sachtouris
#      copyright notice, this list of conditions and the following
13 5eae854d Stavros Sachtouris
#      disclaimer in the documentation and/or other materials
14 5eae854d Stavros Sachtouris
#      provided with the distribution.
15 5eae854d Stavros Sachtouris
#
16 5eae854d Stavros Sachtouris
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 5eae854d Stavros Sachtouris
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 5eae854d Stavros Sachtouris
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 5eae854d Stavros Sachtouris
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 5eae854d Stavros Sachtouris
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 5eae854d Stavros Sachtouris
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 5eae854d Stavros Sachtouris
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 5eae854d Stavros Sachtouris
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 5eae854d Stavros Sachtouris
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 5eae854d Stavros Sachtouris
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 5eae854d Stavros Sachtouris
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 5eae854d Stavros Sachtouris
# POSSIBILITY OF SUCH DAMAGE.
28 5eae854d Stavros Sachtouris
#
29 5eae854d Stavros Sachtouris
# The views and conclusions contained in the software and
30 5eae854d Stavros Sachtouris
# documentation are those of the authors and should not be
31 5eae854d Stavros Sachtouris
# interpreted as representing official policies, either expressed
32 5eae854d Stavros Sachtouris
# or implied, of GRNET S.A.command
33 5eae854d Stavros Sachtouris
34 6069b53b Stavros Sachtouris
import logging
35 6069b53b Stavros Sachtouris
36 6069b53b Stavros Sachtouris
sendlog = logging.getLogger('clients.send')
37 6069b53b Stavros Sachtouris
recvlog = logging.getLogger('clients.recv')
38 6069b53b Stavros Sachtouris
39 234954d1 Stavros Sachtouris
40 5eae854d Stavros Sachtouris
class _command_init(object):
41 5eae854d Stavros Sachtouris
    def __init__(self, arguments={}):
42 e15d78e2 Stavros Sachtouris
        if hasattr(self, 'arguments'):
43 e15d78e2 Stavros Sachtouris
            arguments.update(self.arguments)
44 e15d78e2 Stavros Sachtouris
        self.arguments = dict(arguments)
45 5eae854d Stavros Sachtouris
        try:
46 e15d78e2 Stavros Sachtouris
            self.config = self['config']
47 5a37a189 Stavros Sachtouris
            #self.config = self.get_argument('config')
48 5eae854d Stavros Sachtouris
        except KeyError:
49 5eae854d Stavros Sachtouris
            pass
50 5eae854d Stavros Sachtouris
51 5a37a189 Stavros Sachtouris
    def __getitem__(self, argterm):
52 5a37a189 Stavros Sachtouris
        """
53 5a37a189 Stavros Sachtouris
        :param argterm: (str) the name/label of an argument in self.arguments
54 5a37a189 Stavros Sachtouris

55 b113e74b Stavros Sachtouris
        :returns: the value of the corresponding Argument (not the argument
56 b113e74b Stavros Sachtouris
            object)
57 5a37a189 Stavros Sachtouris

58 5a37a189 Stavros Sachtouris
        :raises KeyError: if argterm not in self.arguments of this object
59 5a37a189 Stavros Sachtouris
        """
60 b113e74b Stavros Sachtouris
        return self.arguments[argterm].value
61 5a37a189 Stavros Sachtouris
62 5a37a189 Stavros Sachtouris
    def __setitem__(self, argterm, arg):
63 5a37a189 Stavros Sachtouris
        """Install an argument as argterm
64 5a37a189 Stavros Sachtouris
        If argterm points to another argument, the other argument is lost
65 5a37a189 Stavros Sachtouris

66 5a37a189 Stavros Sachtouris
        :param argterm: (str)
67 5a37a189 Stavros Sachtouris

68 5a37a189 Stavros Sachtouris
        :param arg: (Argument)
69 5a37a189 Stavros Sachtouris
        """
70 5a37a189 Stavros Sachtouris
        if not hasattr(self, 'arguments'):
71 5a37a189 Stavros Sachtouris
            self.arguments = {}
72 5a37a189 Stavros Sachtouris
        self.arguments[argterm] = arg
73 5a37a189 Stavros Sachtouris
74 b113e74b Stavros Sachtouris
    def get_argument_object(self, argterm):
75 b113e74b Stavros Sachtouris
        """
76 b113e74b Stavros Sachtouris
        :param argterm: (str) the name/label of an argument in self.arguments
77 b113e74b Stavros Sachtouris

78 b113e74b Stavros Sachtouris
        :returns: the arument object
79 b113e74b Stavros Sachtouris

80 b113e74b Stavros Sachtouris
        :raises KeyError: if argterm not in self.arguments of this object
81 b113e74b Stavros Sachtouris
        """
82 b113e74b Stavros Sachtouris
        return self.arguments[argterm]
83 b113e74b Stavros Sachtouris
84 5eae854d Stavros Sachtouris
    def get_argument(self, argterm):
85 5a37a189 Stavros Sachtouris
        """
86 5a37a189 Stavros Sachtouris
        :param argterm: (str) the name/label of an argument in self.arguments
87 5a37a189 Stavros Sachtouris

88 5a37a189 Stavros Sachtouris
        :returns: the value of the arument object
89 5a37a189 Stavros Sachtouris

90 5a37a189 Stavros Sachtouris
        :raises KeyError: if argterm not in self.arguments of this object
91 5a37a189 Stavros Sachtouris
        """
92 e15d78e2 Stavros Sachtouris
        return self[argterm]