View | Details | Raw Unified | Return to bug 38938
Collapse All | Expand All

(-)a/base/univention-config-registry/python/univention/config_registry/backend.py (-4 / +15 lines)
 Lines 67-73   def exception_occured(out=sys.stderr): Link Here 
67
	sys.exit(1)
67
	sys.exit(1)
68
68
69
69
70
SCOPE = ['normal', 'ldap', 'schedule', 'forced', 'custom']
70
SCOPE = ['normal', 'ldap', 'schedule', 'forced', 'custom', 'default']
71
71
72
72
73
if MYPY:
73
if MYPY:
 Lines 84-97   class ConfigRegistry(MM): Link Here 
84
	:param filename: File name for text database file.
84
	:param filename: File name for text database file.
85
	:param write_registry: The UCR level used for writing.
85
	:param write_registry: The UCR level used for writing.
86
	"""
86
	"""
87
	NORMAL, LDAP, SCHEDULE, FORCED, CUSTOM = range(5)
87
	NORMAL, LDAP, SCHEDULE, FORCED, CUSTOM, DEFAULTS = range(6)
88
	LAYER_PRIORITIES = (FORCED, SCHEDULE, LDAP, NORMAL, CUSTOM)
88
	LAYER_PRIORITIES = (FORCED, SCHEDULE, LDAP, NORMAL, CUSTOM, DEFAULTS)
89
	PREFIX = '/etc/univention'
89
	PREFIX = '/etc/univention'
90
	BASES = {
90
	BASES = {
91
		NORMAL: 'base.conf',
91
		NORMAL: 'base.conf',
92
		LDAP: 'base-ldap.conf',
92
		LDAP: 'base-ldap.conf',
93
		SCHEDULE: 'base-schedule.conf',
93
		SCHEDULE: 'base-schedule.conf',
94
		FORCED: 'base-forced.conf',
94
		FORCED: 'base-forced.conf',
95
		DEFAULTS: 'base-defaults.conf',
95
	}
96
	}
96
97
97
	def __init__(self, filename=None, write_registry=NORMAL):
98
	def __init__(self, filename=None, write_registry=NORMAL):
 Lines 124-129   class ConfigRegistry(MM): Link Here 
124
			filename = self.file
125
			filename = self.file
125
		else:
126
		else:
126
			filename = os.path.join(ConfigRegistry.PREFIX, ConfigRegistry.BASES[reg])
127
			filename = os.path.join(ConfigRegistry.PREFIX, ConfigRegistry.BASES[reg])
128
		if reg == ConfigRegistry.DEFAULTS:
129
			return _DefaultConfigRegistry(self, filename=filename)
127
		return _ConfigRegistry(filename=filename)
130
		return _ConfigRegistry(filename=filename)
128
131
129
	def load(self):
132
	def load(self):
 Lines 293-299   class ConfigRegistry(MM): Link Here 
293
		Check if registry key is set.
296
		Check if registry key is set.
294
297
295
		.. deprecated:: 3.1
298
		.. deprecated:: 3.1
296
		    Use `in`.
299
			Use `in`.
297
		"""
300
		"""
298
		if write_registry_only:
301
		if write_registry_only:
299
			registry = self._registry[self.scope]
302
			registry = self._registry[self.scope]
 Lines 660-663   class _ConfigRegistry(dict): Link Here 
660
		"""Return sub registry content as string."""
663
		"""Return sub registry content as string."""
661
		return '\n'.join(['%s: %s' % (key, self.remove_invalid_chars(val)) for key, val in sorted(self.items())])
664
		return '\n'.join(['%s: %s' % (key, self.remove_invalid_chars(val)) for key, val in sorted(self.items())])
662
665
666
667
class _DefaultConfigRegistry(_ConfigRegistry):
668
669
	def __init__(self, parent, filename=None):
670
		super(_DefaultConfigRegistry, self).__init__(filename)
671
		self.parent = parent
672
673
663
# vim:set sw=4 ts=4 noet:
674
# vim:set sw=4 ts=4 noet:
(-)a/base/univention-config-registry/python/univention/config_registry/frontend.py (-13 / +24 lines)
 Lines 37-43   import os Link Here 
37
import sys
37
import sys
38
import re
38
import re
39
import time
39
import time
40
from univention.config_registry.backend import exception_occured, SCOPE, ConfigRegistry
40
from univention.config_registry.backend import exception_occured, SCOPE, ConfigRegistry, _DefaultConfigRegistry
41
from univention.config_registry.handler import run_filter, ConfigHandlers
41
from univention.config_registry.handler import run_filter, ConfigHandlers
42
from univention.config_registry.misc import validate_key, escape_value
42
from univention.config_registry.misc import validate_key, escape_value
43
from univention.config_registry.filters import filter_shell, filter_keys_only, filter_sort
43
from univention.config_registry.filters import filter_shell, filter_keys_only, filter_sort
 Lines 306-311   def handler_register(args, opts=dict()): Link Here 
306
	# diversion is (re-)done when >= 1.
306
	# diversion is (re-)done when >= 1.
307
	handlers.register(args[0], ucr)
307
	handlers.register(args[0], ucr)
308
	# handlers.commit((ucr, {}))
308
	# handlers.commit((ucr, {}))
309
	_register_variable_default_values(ucr)
309
310
310
311
311
def handler_unregister(args, opts=dict()):
312
def handler_unregister(args, opts=dict()):
 Lines 323-328   def handler_unregister(args, opts=dict()): Link Here 
323
	cur = handlers.update()  # cache must be current
324
	cur = handlers.update()  # cache must be current
324
	obsolete = handlers.unregister(args[0], ucr)
325
	obsolete = handlers.unregister(args[0], ucr)
325
	handlers.update_divert(cur - obsolete)
326
	handlers.update_divert(cur - obsolete)
327
	_register_variable_default_values(ucr)
326
328
327
329
328
def handler_filter(args, opts=dict()):
330
def handler_filter(args, opts=dict()):
 Lines 362-372   def handler_search(args, opts=dict()): Link Here 
362
			print('E: invalid regular expression: %s' % (ex,), file=sys.stderr)
364
			print('E: invalid regular expression: %s' % (ex,), file=sys.stderr)
363
			sys.exit(1)
365
			sys.exit(1)
364
366
365
	# Import located here, because on module level, a circular import would be
367
	info = _get_config_registry_info()
366
	# created
367
	import univention.config_registry_info as cri  # pylint: disable-msg=W0403
368
	cri.set_language('en')
369
	info = cri.ConfigRegistryInfo(install_mode=False)
370
368
371
	category = opts.get('category', None)
369
	category = opts.get('category', None)
372
	if category and not info.get_category(category):
370
	if category and not info.get_category(category):
 Lines 492-502   def handler_info(args, opts=dict()): Link Here 
492
	"""
490
	"""
493
	ucr = ConfigRegistry()
491
	ucr = ConfigRegistry()
494
	ucr.load()
492
	ucr.load()
495
	# Import located here, because on module level, a circular import would be
493
	info = _get_config_registry_info()
496
	# created
497
	import univention.config_registry_info as cri  # pylint: disable-msg=W0403
498
	cri.set_language('en')
499
	info = cri.ConfigRegistryInfo(install_mode=False)
500
494
501
	for arg in args:
495
	for arg in args:
502
		try:
496
		try:
 Lines 610-615   def missing_parameter(action): Link Here 
610
	sys.exit(1)
604
	sys.exit(1)
611
605
612
606
607
def _get_config_registry_info():
608
	# Import located here, because on module level, a circular import would be
609
	# created
610
	import univention.config_registry_info as cri  # pylint: disable-msg=W0403
611
	cri.set_language('en')
612
	return cri.ConfigRegistryInfo(install_mode=False)
613
614
615
def _register_variable_default_values(ucr):
616
	"""Create base-default.conf layer containig all default values"""
617
	info = _get_config_registry_info()
618
	defaults = _DefaultConfigRegistry(ucr, '/etc/univention/base-defaults.conf')
619
	for key, variable in info.get_variables().items():
620
		value = variable.get('Default')
621
		if value:
622
			defaults[key] = value
623
	defaults.save()
624
625
613
HANDLERS = {
626
HANDLERS = {
614
	'set': (handler_set, 1),
627
	'set': (handler_set, 1),
615
	'unset': (handler_unset, 1),
628
	'unset': (handler_unset, 1),
616
- 
617
UCR variables
629
UCR variables
618
--
619
.../python/univention/config_registry/backend.py   | 31 ++++++++++++++++++++++
630
.../python/univention/config_registry/backend.py   | 31 ++++++++++++++++++++++
620
1 file changed, 31 insertions(+)
631
1 file changed, 31 insertions(+)
(-)a/base/univention-config-registry/python/univention/config_registry/backend.py (-2 / +31 lines)
 Lines 38-43   import errno Link Here 
38
import time
38
import time
39
from collections import MutableMapping
39
from collections import MutableMapping
40
import six
40
import six
41
42
from univention.config_registry.handler import run_filter
43
41
try:
44
try:
42
	from typing import overload, Any, Dict, IO, Iterator, List, NoReturn, Optional, Set, Tuple, Type, TypeVar, Union  # noqa F401
45
	from typing import overload, Any, Dict, IO, Iterator, List, NoReturn, Optional, Set, Tuple, Type, TypeVar, Union  # noqa F401
43
	from types import TracebackType  # noqa
46
	from types import TracebackType  # noqa
 Lines 670-674   class _DefaultConfigRegistry(_ConfigRegistry): Link Here 
670
		super(_DefaultConfigRegistry, self).__init__(filename)
673
		super(_DefaultConfigRegistry, self).__init__(filename)
671
		self.parent = parent
674
		self.parent = parent
672
675
676
	def __getitem__(self, key):  # type: ignore
677
		value = super(_DefaultConfigRegistry, self).__getitem__(key)
678
		try:
679
			return run_filter(value, self.parent)
680
		except RuntimeError:  # maximum recursion depth exceeded
681
			return ''
682
683
	# Implement the dict contract...
684
	# TODO: copy(), viewitems(), viewvalues()
685
686
	def get(self, key, default=None):
687
		try:
688
			return self[key]
689
		except KeyError:
690
			return default
691
692
	def iteritems(self):
693
		return dict((key, self[key]) for key in self).iteritems()
694
695
	def items(self):
696
		return dict((key, self[key]) for key in self).items()
697
698
	def values(self):
699
		return dict((key, self[key]) for key in self).values()
700
701
	def itervalues(self):
702
		return dict((key, self[key]) for key in self).itervalues()
703
673
704
674
# vim:set sw=4 ts=4 noet:
705
# vim:set sw=4 ts=4 noet:
675
- 
676
--
677
.../python/univention/config_registry/frontend.py            | 12 ++++++++----
706
.../python/univention/config_registry/frontend.py            | 12 ++++++++----
678
1 file changed, 8 insertions(+), 4 deletions(-)
707
1 file changed, 8 insertions(+), 4 deletions(-)
(-)a/base/univention-config-registry/python/univention/config_registry/frontend.py (-6 / +8 lines)
 Lines 67-73   __all__ = [ Link Here 
67
67
68
REPLOG_FILE = '/var/log/univention/config-registry.replog'
68
REPLOG_FILE = '/var/log/univention/config-registry.replog'
69
69
70
_SHOW_EMPTY, _SHOW_DESCRIPTION, _SHOW_SCOPE, _SHOW_CATEGORIES = (1 << _ for _ in range(4))
70
_SHOW_EMPTY, _SHOW_DESCRIPTION, _SHOW_SCOPE, _SHOW_CATEGORIES, _SHOW_DEFAULT = (1 << _ for _ in range(5))
71
71
72
72
73
class UnknownKeyException(Exception):
73
class UnknownKeyException(Exception):
 Lines 430-445   def handler_get(args, opts=dict()): Link Here 
430
		yield ucr.get(args[0], '')
430
		yield ucr.get(args[0], '')
431
431
432
432
433
def variable_info_string(key, value, variable_info, scope=None, details=_SHOW_DESCRIPTION):
433
def variable_info_string(key, value, variable_info, scope=None, details=_SHOW_DESCRIPTION, default=None):
434
	# type: (str, Optional[str], Any, int, int) -> str
434
	# type: (str, Optional[str], Any, int, int) -> str
435
	"""
435
	"""
436
	Format UCR variable key, value, description, scope and categories.
436
	Format UCR variable key, value, description, scope, categories and default value.
437
437
438
	:param key: UCR variable name.
438
	:param key: UCR variable name.
439
	:param value: UCR variable value.
439
	:param value: UCR variable value.
440
	:param variable_info: Description object.
440
	:param variable_info: Description object.
441
	:param scope: UCS layer.
441
	:param scope: UCS layer.
442
	:param details: bit-field for detail-level.
442
	:param details: bit-field for detail-level.
443
	:param default: UCR variable default value.
443
	:returns: formatted string
444
	:returns: formatted string
444
	"""
445
	"""
445
	if value is None and not variable_info:
446
	if value is None and not variable_info:
 Lines 474-479   def variable_info_string(key, value, variable_info, scope=None, details=_SHOW_DE Link Here 
474
	if variable_info and _SHOW_CATEGORIES & details:
475
	if variable_info and _SHOW_CATEGORIES & details:
475
		info.append(' Categories: ' + variable_info.get('categories', 'none'))
476
		info.append(' Categories: ' + variable_info.get('categories', 'none'))
476
477
478
	if variable_info and _SHOW_DEFAULT & details:
479
		info.append(' Default: ' + variable_info.get('default', '(not set)'))
480
477
	if (_SHOW_CATEGORIES | _SHOW_DESCRIPTION) & details:
481
	if (_SHOW_CATEGORIES | _SHOW_DESCRIPTION) & details:
478
		info.append('')
482
		info.append('')
479
483
 Lines 497-503   def handler_info(args, opts=dict()): Link Here 
497
			yield variable_info_string(
501
			yield variable_info_string(
498
				arg, ucr.get(arg, None),
502
				arg, ucr.get(arg, None),
499
				info.get_variable(arg),
503
				info.get_variable(arg),
500
				details=_SHOW_EMPTY | _SHOW_DESCRIPTION | _SHOW_CATEGORIES)
504
				details=_SHOW_EMPTY | _SHOW_DESCRIPTION | _SHOW_CATEGORIES | _SHOW_DEFAULT)
501
		except UnknownKeyException as ex:
505
		except UnknownKeyException as ex:
502
			print(ex, file=sys.stderr)
506
			print(ex, file=sys.stderr)
503
507
504
- 
505
--
506
.../univention-management-console-module-ucr/umc/js/ucr.js     | 10 +++++++++-
508
.../univention-management-console-module-ucr/umc/js/ucr.js     | 10 +++++++++-
507
1 file changed, 9 insertions(+), 1 deletion(-)
509
1 file changed, 9 insertions(+), 1 deletion(-)
(-)a/management/univention-management-console-module-ucr/umc/js/ucr.js (-2 / +9 lines)
 Lines 99-104   define([ Link Here 
99
	//			description: _( 'Categories that the UCR variable is associated with' ),
99
	//			description: _( 'Categories that the UCR variable is associated with' ),
100
	//			label: _( 'Categories' ),
100
	//			label: _( 'Categories' ),
101
	//			dynamicValues: 'ucr/categories'
101
	//			dynamicValues: 'ucr/categories'
102
			}, {
103
				type: TextBox,
104
				name: 'default',
105
				description: _('Pattern of the default value of the UCR variable if it is unset'),
106
				readonly: true,
107
				label: _('Default value (pattern)')
102
			}];
108
			}];
103
109
104
			var buttons = [{
110
			var buttons = [{
 Lines 116-122   define([ Link Here 
116
				})
122
				})
117
			}];
123
			}];
118
124
119
			var layout = ['key', 'value', 'description'];//, ['categories']];
125
			var layout = ['key', 'value', 'description', 'default'];//, ['categories']];
120
126
121
			this._form = this.own(new Form({
127
			this._form = this.own(new Form({
122
				widgets: widgets,
128
				widgets: widgets,
 Lines 173-178   define([ Link Here 
173
		newVariable: function() {
179
		newVariable: function() {
174
			this.set('title', _('Add UCR variable'));
180
			this.set('title', _('Add UCR variable'));
175
			this._form._widgets.key.set('disabled', false);
181
			this._form._widgets.key.set('disabled', false);
182
			this._form._widgets.default.set('visible', false);
176
			this.clearForm();
183
			this.clearForm();
177
			this.standby(false);
184
			this.standby(false);
178
			this.show();
185
			this.show();
 Lines 181-186   define([ Link Here 
181
		loadVariable: function(ucrVariable) {
188
		loadVariable: function(ucrVariable) {
182
			this.set('title', _('Edit UCR variable'));
189
			this.set('title', _('Edit UCR variable'));
183
			this._form._widgets.key.set('disabled', true);
190
			this._form._widgets.key.set('disabled', true);
191
			this._form._widgets.default.set('visible', true);
184
192
185
			this.standby(true);
193
			this.standby(true);
186
			this.show();
194
			this.show();
187
- 

Return to bug 38938