Revision 534e7bbb
b/kamaki/cli/__init__.py | ||
---|---|---|
244 | 244 |
_check_config_version(_cnf.value) |
245 | 245 |
|
246 | 246 |
global _colors |
247 |
_colors = _cnf.value.get_global('colors')
|
|
247 |
_colors = _cnf.value.get('global', 'colors')
|
|
248 | 248 |
if not (stdout.isatty() and _colors == 'on'): |
249 | 249 |
from kamaki.cli.utils import remove_colors |
250 | 250 |
remove_colors() |
... | ... | |
473 | 473 |
|
474 | 474 |
def run_one_cmd(exe_string, parser, cloud): |
475 | 475 |
global _history |
476 |
_history = History(parser.arguments['config'].get_global('history_file'))
|
|
476 |
_history = History(parser.arguments['config'].get('global', 'history_file'))
|
|
477 | 477 |
_history.add(' '.join([exe_string] + argv[1:])) |
478 | 478 |
from kamaki.cli import one_command |
479 | 479 |
one_command.run(cloud, parser, _help) |
... | ... | |
515 | 515 |
exit(0) |
516 | 516 |
|
517 | 517 |
_cnf = parser.arguments['config'] |
518 |
log_file = _cnf.get_global('log_file')
|
|
518 |
log_file = _cnf.get('global', 'log_file')
|
|
519 | 519 |
if log_file: |
520 | 520 |
logger.set_log_filename(log_file) |
521 | 521 |
global filelog |
b/kamaki/cli/argument/__init__.py | ||
---|---|---|
126 | 126 |
k.endswith(suffix))] |
127 | 127 |
|
128 | 128 |
def get_global(self, option): |
129 |
return self.value.get_global(option)
|
|
129 |
return self.value.get('global', option)
|
|
130 | 130 |
|
131 | 131 |
def get_cloud(self, cloud, option): |
132 | 132 |
return self.value.get_cloud(cloud, option) |
b/kamaki/cli/argument/test.py | ||
---|---|---|
152 | 152 |
('config_cli', 'config'), |
153 | 153 |
('image_cli', 'image'), |
154 | 154 |
('history_cli', 'history')): |
155 |
with patch('%s.get_global' % cnf_path, return_value=v) as gg:
|
|
155 |
with patch('%s.get' % cnf_path, return_value=v) as gg: |
|
156 | 156 |
self.assertEqual(c.get_global(k), v) |
157 |
self.assertEqual(gg.mock_calls[-1], call(k)) |
|
157 |
self.assertEqual(gg.mock_calls[-1], call('global', k))
|
|
158 | 158 |
|
159 | 159 |
def test_get_cloud(self): |
160 | 160 |
c = argument._config_arg |
b/kamaki/cli/command_shell.py | ||
---|---|---|
305 | 305 |
self.cloud = cloud |
306 | 306 |
self._parser = parser |
307 | 307 |
self._history = History( |
308 |
parser.arguments['config'].get_global('history_file'))
|
|
308 |
parser.arguments['config'].get('global', 'history_file'))
|
|
309 | 309 |
if path: |
310 | 310 |
cmd = self.cmd_tree.get_command(path) |
311 | 311 |
intro = cmd.path.replace('_', ' ') |
b/kamaki/cli/commands/__init__.py | ||
---|---|---|
155 | 155 |
def _set_log_params(self): |
156 | 156 |
try: |
157 | 157 |
self.client.LOG_TOKEN = ( |
158 |
self['config'].get_global('log_token').lower() == 'on')
|
|
158 |
self['config'].get('global', 'log_token').lower() == 'on')
|
|
159 | 159 |
except Exception as e: |
160 | 160 |
log.debug('Failed to read custom log_token setting:' |
161 | 161 |
'%s\n default for log_token is off' % e) |
162 | 162 |
try: |
163 | 163 |
self.client.LOG_DATA = ( |
164 |
self['config'].get_global('log_data').lower() == 'on')
|
|
164 |
self['config'].get('global', 'log_data').lower() == 'on')
|
|
165 | 165 |
except Exception as e: |
166 | 166 |
log.debug('Failed to read custom log_data setting:' |
167 | 167 |
'%s\n default for log_data is off' % e) |
168 | 168 |
try: |
169 | 169 |
self.client.LOG_PID = ( |
170 |
self['config'].get_global('log_pid').lower() == 'on')
|
|
170 |
self['config'].get('global', 'log_pid').lower() == 'on')
|
|
171 | 171 |
except Exception as e: |
172 | 172 |
log.debug('Failed to read custom log_pid setting:' |
173 | 173 |
'%s\n default for log_pid is off' % e) |
174 | 174 |
|
175 | 175 |
def _update_max_threads(self): |
176 | 176 |
if getattr(self, 'client', None): |
177 |
max_threads = int(self['config'].get_global('max_threads'))
|
|
177 |
max_threads = int(self['config'].get('global', 'max_threads'))
|
|
178 | 178 |
assert max_threads > 0, 'invalid max_threads config option' |
179 | 179 |
self.client.MAX_THREADS = max_threads |
180 | 180 |
|
b/kamaki/cli/commands/history.py | ||
---|---|---|
75 | 75 |
@errors.generic.all |
76 | 76 |
@errors.history.init |
77 | 77 |
def _run(self): |
78 |
self.history = History(self.config.get_global('history_file'))
|
|
78 |
self.history = History(self.config.get('global', 'history_file'))
|
|
79 | 79 |
|
80 | 80 |
def main(self): |
81 | 81 |
self._run() |
b/kamaki/cli/config/__init__.py | ||
---|---|---|
292 | 292 |
raise KeyError('Cloud "%s" does not exist' % cloud) |
293 | 293 |
return r[option] |
294 | 294 |
|
295 |
def get_global(self, option): |
|
296 |
return self.get('global', option) |
|
297 |
|
|
298 | 295 |
def set_cloud(self, cloud, option, value): |
299 | 296 |
try: |
300 | 297 |
d = self.get(CLOUD_PREFIX, cloud) or dict() |
... | ... | |
303 | 300 |
d[option] = value |
304 | 301 |
self.set(CLOUD_PREFIX, cloud, d) |
305 | 302 |
|
306 |
def set_global(self, option, value): |
|
307 |
self.set('global', option, value) |
|
308 |
|
|
309 | 303 |
def _load_defaults(self): |
310 | 304 |
for section, options in DEFAULTS.items(): |
311 | 305 |
for option, val in options.items(): |
b/kamaki/cli/config/test.py | ||
---|---|---|
300 | 300 |
with patch('kamaki.cli.config.Config.get', return_value=0) as get: |
301 | 301 |
self.assertRaises(KeyError, _cnf.get_cloud, 'mycloud', 'opt1') |
302 | 302 |
|
303 |
def test_get_global(self): |
|
304 |
from kamaki.cli.config import Config |
|
305 |
|
|
306 |
_cnf = Config(path=self.f.name) |
|
307 |
with patch('kamaki.cli.config.Config.get', return_value='val') as get: |
|
308 |
self.assertEqual('val', _cnf.get_global('opt')) |
|
309 |
get.assert_called_once_with('global', 'opt') |
|
310 |
|
|
311 | 303 |
@patch('kamaki.cli.config.Config.set') |
312 | 304 |
def test_set_cloud(self, c_set): |
313 | 305 |
from kamaki.cli.config import Config, CLOUD_PREFIX |
... | ... | |
336 | 328 |
self.assertEqual( |
337 | 329 |
c_set.mock_calls[-1], call(CLOUD_PREFIX, 'mycloud', d)) |
338 | 330 |
|
339 |
def test_set_global(self): |
|
340 |
from kamaki.cli.config import Config |
|
341 |
_cnf = Config(path=self.f.name) |
|
342 |
|
|
343 |
with patch('kamaki.cli.config.Config.set') as c_set: |
|
344 |
_cnf.set_global('opt', 'val') |
|
345 |
c_set.assert_called_once_with('global', 'opt', 'val') |
|
346 |
|
|
347 | 331 |
def test__load_defaults(self): |
348 | 332 |
from kamaki.cli.config import Config, DEFAULTS |
349 | 333 |
_cnf = Config(path=self.f.name) |
Also available in: Unified diff