Revision e2c178f2
b/snf-common/synnefo/settings/setup.py | ||
---|---|---|
260 | 260 |
|
261 | 261 |
__str__ = __repr__ |
262 | 262 |
|
263 |
def present_as_comment(self): |
|
263 |
def present_as_comment(self, runtime=False):
|
|
264 | 264 |
header = "# {name}: type {type}, category '{categ}'" |
265 | 265 |
header = header.format(name=self.setting_name, |
266 | 266 |
type=self.setting_type.upper(), |
... | ... | |
276 | 276 |
|
277 | 277 |
example_value = self.example_value |
278 | 278 |
default_value = self.default_value |
279 |
runtime_value = self.runtime_value |
|
279 | 280 |
if example_value != default_value: |
280 | 281 |
example = "Example value: {0}" |
281 | 282 |
example = example.format(pformat(example_value)).split('\n') |
... | ... | |
286 | 287 |
assignment = assignment.format(name=self.setting_name, |
287 | 288 |
value=pformat(default_value)) |
288 | 289 |
assignment = [("#" + s) for s in assignment.split('\n')] |
290 |
if runtime and self.configured_value is not Setting.NoValue \ |
|
291 |
and runtime_value != self.default_value: |
|
292 |
runtime_assignment = "{name} = {value}" |
|
293 |
runtime_assignment = runtime_assignment.format( |
|
294 |
name=self.setting_name, |
|
295 |
value=pformat(self.runtime_value)) |
|
296 |
assignment += [runtime_assignment] |
|
289 | 297 |
|
290 | 298 |
return '\n'.join(chain(header, ['#'], |
291 | 299 |
description, ['#'], |
b/snf-webproject/synnefo/webproject/management/commands/settings.py | ||
---|---|---|
105 | 105 |
default=False, |
106 | 106 |
help=("Display full setting details")), |
107 | 107 |
make_option( |
108 |
"-r", "--runtime", |
|
109 |
dest="printout_runtime", |
|
110 |
action="store_true", |
|
111 |
default=False, |
|
112 |
help=("Append runtime values in printout.")), |
|
113 |
make_option( |
|
108 | 114 |
"-p", "--printout", |
109 | 115 |
dest="printout", |
110 | 116 |
action="store_true", |
... | ... | |
309 | 315 |
line = format_str.format(**format_args) + eol |
310 | 316 |
print line |
311 | 317 |
|
312 |
def display_printout(self, display_settings_list): |
|
318 |
def display_printout(self, display_settings_list, runtime=False):
|
|
313 | 319 |
for name, setting in display_settings_list: |
314 |
comment = setting.present_as_comment() + '\n' |
|
320 |
comment = setting.present_as_comment(runtime=runtime) + '\n'
|
|
315 | 321 |
print comment |
316 | 322 |
|
317 |
def printout_files(self, display_settings_list, path): |
|
323 |
def printout_files(self, display_settings_list, path, runtime=False):
|
|
318 | 324 |
if not isdir(path): |
319 | 325 |
m = "Cannot find directory '{path}'".format(path=path) |
320 | 326 |
raise CommandError(m) |
... | ... | |
341 | 347 |
conffile.close() |
342 | 348 |
conffile = open(filepath, "a") |
343 | 349 |
old_filepath = filepath |
344 |
conffile.write(setting.present_as_comment()) |
|
350 |
conffile.write(setting.present_as_comment(runtime=runtime))
|
|
345 | 351 |
conffile.write('\n') |
346 | 352 |
|
347 | 353 |
def handle(self, *args, **options): |
... | ... | |
371 | 377 |
display_settings_list = sort_method(display_settings) |
372 | 378 |
|
373 | 379 |
if options['printout']: |
374 |
self.display_printout(display_settings_list) |
|
380 |
self.display_printout(display_settings_list, |
|
381 |
options['printout_runtime']) |
|
375 | 382 |
elif options['printout_files']: |
376 | 383 |
self.printout_files(display_settings_list, |
377 |
options['printout_files']) |
|
384 |
options['printout_files'], |
|
385 |
options['printout_runtime']) |
|
378 | 386 |
else: |
379 | 387 |
self.display_console(display_settings_list, options) |
Also available in: Unified diff