root / kamaki / cli / commands / config_cli.py @ 7493ccb6
History | View | Annotate | Download (3 kB)
1 |
# Copyright 2011-2012 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 kamaki.cli import command, set_api_description |
35 |
set_api_description('config', 'Configuration commands') |
36 |
|
37 |
@command()
|
38 |
class config_list(object): |
39 |
"""List configuration options"""
|
40 |
|
41 |
def update_parser(self, parser): |
42 |
parser.add_argument('-a', dest='all', action='store_true', |
43 |
default=False, help='include default values') |
44 |
|
45 |
def main(self): |
46 |
include_defaults = self.args.all
|
47 |
for section in sorted(self.config.sections()): |
48 |
items = self.config.items(section, include_defaults)
|
49 |
for key, val in sorted(items): |
50 |
print('%s.%s = %s' % (section, key, val))
|
51 |
|
52 |
@command()
|
53 |
class config_get(object): |
54 |
"""Show a configuration option"""
|
55 |
|
56 |
def main(self, option): |
57 |
section, sep, key = option.rpartition('.')
|
58 |
section = section or 'global' |
59 |
value = self.config.get(section, key)
|
60 |
if value is not None: |
61 |
print(value) |
62 |
|
63 |
@command()
|
64 |
class config_set(object): |
65 |
"""Set a configuration option"""
|
66 |
|
67 |
def main(self, option, value): |
68 |
section, sep, key = option.rpartition('.')
|
69 |
section = section or 'globail' |
70 |
self.config.set(section, key, value)
|
71 |
self.config.write()
|
72 |
|
73 |
@command()
|
74 |
class config_delete(object): |
75 |
"""Delete a configuration option (and use the default value)"""
|
76 |
|
77 |
def main(self, option): |
78 |
section, sep, key = option.rpartition('.')
|
79 |
section = section or 'global' |
80 |
self.config.remove_option(section, key)
|
81 |
self.config.write()
|