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

(-)a/branches/ucs-3.1/ucs/base/univention-config-registry/debian/changelog (+6 lines)
 Lines 1-3    Link Here 
1
univention-config-registry (8.0.4-10) unstable; urgency=low
2
3
  * Fix locking and data corruption issue in UCR (Bug #15723)
4
5
 -- Philipp Hahn <hahn@univention.de>  Wed, 14 Nov 2012 17:32:42 +0100
6
1
univention-config-registry (8.0.4-9) unstable; urgency=low
7
univention-config-registry (8.0.4-9) unstable; urgency=low
2
8
3
  * Fix ucr unregister for Multifile (Bug #26476)
9
  * Fix ucr unregister for Multifile (Bug #26476)
(-)a/branches/ucs-3.1/ucs/base/univention-config-registry/python/univention/config_registry/backend.py (-55 / +68 lines)
 Lines 94-104   class ConfigRegistry(dict): Link Here 
94
					ConfigRegistry.BASES[reg])
94
					ConfigRegistry.BASES[reg])
95
		return _ConfigRegistry(filename=filename)
95
		return _ConfigRegistry(filename=filename)
96
96
97
	def load(self):
97
	def load(self, writable=False):
98
		"""Load registry from file."""
98
		"""Load registry from file."""
99
		for reg in self._registry:
99
		for reg in self._registry:
100
			if isinstance(reg, _ConfigRegistry):
100
			if isinstance(reg, _ConfigRegistry):
101
				reg.load()
101
				reg.load(writable and reg is self._write_registry)
102
		strict = self.is_true('ucr/encoding/strict')
102
		strict = self.is_true('ucr/encoding/strict')
103
		for reg in self._registry:
103
		for reg in self._registry:
104
			if isinstance(reg, _ConfigRegistry):
104
			if isinstance(reg, _ConfigRegistry):
 Lines 108-121   class ConfigRegistry(dict): Link Here 
108
		"""Save registry to file."""
108
		"""Save registry to file."""
109
		self._write_registry.save()
109
		self._write_registry.save()
110
110
111
	def lock(self):
112
		"""Lock registry file."""
113
		self._write_registry.lock()
114
115
	def unlock(self):
116
		"""Un-lock registry file."""
117
		self._write_registry.unlock()
118
119
	def __delitem__(self, key):
111
	def __delitem__(self, key):
120
		"""Delete registry key."""
112
		"""Delete registry key."""
121
		del self._write_registry[key]
113
		del self._write_registry[key]
 Lines 241-252   class _ConfigRegistry(dict): Link Here 
241
		self.file = filename or '/etc/univention/base.conf'
233
		self.file = filename or '/etc/univention/base.conf'
242
		self.__create_base_conf()
234
		self.__create_base_conf()
243
		self.backup_file = self.file + '.bak'
235
		self.backup_file = self.file + '.bak'
244
		self.lock_filename = self.file + '.lock'
245
		# will be set by <ConfigRegistry> for each <_ConfigRegistry> - <True>
236
		# will be set by <ConfigRegistry> for each <_ConfigRegistry> - <True>
246
		# means the backend files are valid UTF-8 and should stay that way -->
237
		# means the backend files are valid UTF-8 and should stay that way -->
247
		# only accept valid UTF-8
238
		# only accept valid UTF-8
248
		self.strict_encoding = False
239
		self.strict_encoding = False
249
		self.lock_file = None
240
		self.reg_file = None
250
241
251
	def __create_base_conf(self):
242
	def __create_base_conf(self):
252
		"""Create sub registry file."""
243
		"""Create sub registry file."""
 Lines 262-318   class _ConfigRegistry(dict): Link Here 
262
	def __load_file(self, reg_file):
253
	def __load_file(self, reg_file):
263
		"""Load sub registry from opened file."""
254
		"""Load sub registry from opened file."""
264
		self.clear()
255
		self.clear()
265
		for line in reg_file.readlines():
256
		nr = -1
257
		for nr, line in enumerate(reg_file):
266
			line = re.sub(r'^[^:]*#.*$', "", line)
258
			line = re.sub(r'^[^:]*#.*$', "", line)
267
			if line == '':
259
			if not line:
268
				continue
260
				continue
269
			if line.find(': ') == -1:
261
			try:
262
				key, value = line.split(': ', 1)
263
			except ValueError:
270
				continue
264
				continue
265
			else:
266
				self[key] = value.strip()
267
		return nr >= 2
271
268
272
			key, value = line.split(': ', 1)
269
	def load(self, writable=False):
273
			value = value.strip()
274
			if len(value) == 0:  # if variable was set without an value
275
				value = ''
276
277
			self[key] = value
278
279
	def load(self):
280
		"""Load sub registry from file."""
270
		"""Load sub registry from file."""
281
		import_failed = False
282
		try:
271
		try:
283
			reg_file = open(self.file, 'r')
272
			if writable:
273
				self.reg_file = reg_file = os.fdopen(os.open(self.file, os.O_RDWR | os.O_CREAT, 0644), 'w')
274
				fcntl.flock(self.reg_file.fileno(), fcntl.LOCK_EX)
275
				if self.__load_file(reg_file):
276
					return
277
			else:
278
				reg_file = open(self.file, 'r')
279
				try:
280
					fcntl.flock(reg_file.fileno(), fcntl.LOCK_SH)
281
					if self.__load_file(reg_file):
282
						return
283
				finally:
284
					reg_file.close()
284
		except EnvironmentError:
285
		except EnvironmentError:
285
			import_failed = True
286
			pass
286
		else:
287
			if len(reg_file.readlines()) < 3:  # comment or nothing
288
				import_failed = True
289
290
		if import_failed:
291
			try:
292
				reg_file = open(self.backup_file, 'r')
293
			except EnvironmentError:
294
				return
295
287
296
		reg_file.seek(0)
288
		# open or loading failed, try to load backup
297
		self.__load_file(reg_file)
289
		try:
298
		reg_file.close()
290
			bak_file = open(self.backup_file, 'r')
291
			fcntl.flock(bak_file.fileno(), fcntl.LOCK_SH)
292
			self.__load_file(bak_file)
293
			bak_file.close()
294
		except EnvironmentError:
295
			return
299
296
300
		if import_failed:
297
		# Try to write main file
301
			self.__save_file(self.file)
298
		try:
299
			if writable:
300
				self.__save_file(self.reg_file)
301
			else:
302
				reg_file = os.fdopen(os.open(self.file, os.O_RDWR | os.O_CREAT, 0644), 'w')
303
				try:
304
					fcntl.flock(reg_file.fileno(), fcntl.LOCK_EX)
305
					self.__save_file(reg_file)
306
				finally:
307
					reg_file.close()
308
		except EnvironmentError:
309
			pass
302
310
303
	def __save_file(self, filename):
311
	def __save_file(self, reg_file):
304
		"""Save sub registry to file."""
312
		"""Save sub registry to file."""
305
		try:
313
		try:
306
			# open temporary file for writing
314
			reg_file.seek(0)
307
			reg_file = open(filename, 'w')
308
			# write data to file
315
			# write data to file
309
			reg_file.write('# univention_ base.conf\n\n')
316
			reg_file.write('# univention_ base.conf\n\n')
310
			reg_file.write(self.__str__())
317
			reg_file.write(self.__str__())
311
			# flush (meta)data
318
			# flush (meta)data
312
			reg_file.flush()
319
			reg_file.flush()
320
			reg_file.truncate()
313
			os.fsync(reg_file.fileno())
321
			os.fsync(reg_file.fileno())
314
			# close fd
315
			reg_file.close()
316
		except EnvironmentError, ex:
322
		except EnvironmentError, ex:
317
			# suppress certain errors
323
			# suppress certain errors
318
			if ex.errno != errno.EACCES:
324
			if ex.errno != errno.EACCES:
 Lines 320-336   class _ConfigRegistry(dict): Link Here 
320
326
321
	def save(self):
327
	def save(self):
322
		"""Save sub registry to file."""
328
		"""Save sub registry to file."""
323
		for filename in (self.backup_file, self.file):
329
		assert self.reg_file
324
			self.__save_file(filename)
330
		try:
325
331
			bak_file = os.fdopen(os.open(self.backup_file, os.O_RDWR | os.O_CREAT, 0644), 'w')
326
	def lock(self):
332
			try:
327
		"""Lock sub registry file."""
333
				fcntl.flock(bak_file.fileno(), fcntl.LOCK_EX)
328
		self.lock_file = open(self.lock_filename, "a+")
334
				self.__save_file(bak_file)
329
		fcntl.flock(self.lock_file.fileno(), fcntl.LOCK_EX)
335
			finally:
336
				bak_file.close()
330
337
331
	def unlock(self):
338
			try:
332
		"""Un-lock sub registry file."""
339
				self.__save_file(self.reg_file)
333
		self.lock_file.close()
340
			finally:
341
				self.reg_file.close()
342
			self.reg_file = None
343
		except EnvironmentError, ex:
344
			# suppress certain errors
345
			if ex.errno != errno.EACCES:
346
				raise
334
347
335
	def __getitem__(self, key):
348
	def __getitem__(self, key):
336
		"""Return value from sub registry."""
349
		"""Return value from sub registry."""
(-)a/branches/ucs-3.1/ucs/base/univention-config-registry/python/univention/config_registry/frontend.py (-8 / +4 lines)
 Lines 136-144   def handler_set(args, opts=dict(), quiet=False): Link Here 
136
	else:
136
	else:
137
		reg = ConfigRegistry()
137
		reg = ConfigRegistry()
138
138
139
	reg.lock()
139
	reg.load(writable=True)
140
	try:
140
	try:
141
		reg.load()
142
		changed = {}
141
		changed = {}
143
		for arg in args:
142
		for arg in args:
144
			sep_set = arg.find('=')  # set
143
			sep_set = arg.find('=')  # set
 Lines 178-186   def handler_set(args, opts=dict(), quiet=False): Link Here 
178
						print 'Not updating %s' % key
177
						print 'Not updating %s' % key
179
					else:
178
					else:
180
						print 'Not setting %s' % key
179
						print 'Not setting %s' % key
181
		reg.save()
182
	finally:
180
	finally:
183
		reg.unlock()
181
		reg.save()
184
	handlers(changed.keys(), (reg, changed))
182
	handlers(changed.keys(), (reg, changed))
185
183
186
184
 Lines 205-213   def handler_unset(args, opts=dict()): Link Here 
205
	else:
203
	else:
206
		reg = ConfigRegistry()
204
		reg = ConfigRegistry()
207
205
208
	reg.lock()
206
	reg.load(writable=True)
209
	try:
207
	try:
210
		reg.load()
211
		changed = {}
208
		changed = {}
212
		for arg in args:
209
		for arg in args:
213
			if reg.has_key(arg, write_registry_only=True):
210
			if reg.has_key(arg, write_registry_only=True):
 Lines 224-232   def handler_unset(args, opts=dict()): Link Here 
224
			else:
221
			else:
225
				msg = "W: The config registry variable '%s' does not exist"
222
				msg = "W: The config registry variable '%s' does not exist"
226
				print >> sys.stderr, msg % (arg,)
223
				print >> sys.stderr, msg % (arg,)
227
		reg.save()
228
	finally:
224
	finally:
229
		reg.unlock()
225
		reg.save()
230
	handlers(changed.keys(), (reg, changed))
226
	handlers(changed.keys(), (reg, changed))
231
227
232
228
(-)a/branches/ucs-3.1/ucs/base/univention-ssl/debian/changelog (+6 lines)
 Lines 1-3    Link Here 
1
univention-ssl (7.0.5-4) unstable; urgency=low
2
3
  * Fix locking and data corruption issue in UCR (Bug #15723)
4
5
 -- Philipp Hahn <hahn@univention.de>  Wed, 14 Nov 2012 17:32:11 +0100
6
1
univention-ssl (7.0.5-3) unstable; urgency=low
7
univention-ssl (7.0.5-3) unstable; urgency=low
2
8
3
  * Fix errexit (Bug #26572)
9
  * Fix errexit (Bug #26572)
(-)a/branches/ucs-3.1/ucs/base/univention-ssl/univention-certificate-check-validity (-5 / +6 lines)
 Lines 37-43   import calendar Link Here 
37
37
38
from M2Crypto import X509
38
from M2Crypto import X509
39
39
40
from univention.config_registry import ConfigRegistry
40
from univention.config_registry import ConfigRegistry, handler_set
41
41
42
_bc = ConfigRegistry()
42
_bc = ConfigRegistry()
43
_bc.load()
43
_bc.load()
 Lines 68-77   if __name__ == '__main__': Link Here 
68
	days = get_validity_days('/etc/univention/ssl/%s/cert.pem' % fqdn)
68
	days = get_validity_days('/etc/univention/ssl/%s/cert.pem' % fqdn)
69
	days_ca = get_validity_days('/etc/univention/ssl/ucsCA/CAcert.pem')
69
	days_ca = get_validity_days('/etc/univention/ssl/ucsCA/CAcert.pem')
70
70
71
	changes = []
71
	if days and days != _bc.get( 'ssl/validity/host', -1 ):
72
	if days and days != _bc.get( 'ssl/validity/host', -1 ):
72
		_bc[ 'ssl/validity/host' ] = str( days )
73
		changes.append('ssl/validity/host=%d' % (days,))
73
		_bc.save()
74
74
75
	if days_ca and days_ca != _bc.get( 'ssl/validity/root', -1 ):
75
	if days_ca and days_ca != _bc.get( 'ssl/validity/root', -1 ):
76
		_bc[ 'ssl/validity/root' ] = str( days_ca )
76
		changes.append('ssl/validity/root=%d' % (days_cs,))
77
		_bc.save()
77
	if changes:
78
		handler_set(changes)
(-)a/branches/ucs-3.1/ucs/base/univention-system-setup/debian/changelog (+7 lines)
 Lines 1-5    Link Here 
1
univention-system-setup (6.0.51-1) unstable; urgency=low
2
3
  * Fix locking and data corruption issue in UCR (Bug #15723)
4
5
 -- Philipp Hahn <hahn@univention.de>  Wed, 14 Nov 2012 17:32:26 +0100
6
1
univention-system-setup (6.0.50-1) unstable; urgency=low
7
univention-system-setup (6.0.50-1) unstable; urgency=low
2
8
9
3
  * Revert changes in NetworkPage; Bug #28389
10
  * Revert changes in NetworkPage; Bug #28389
4
11
5
 -- Dirk Wiesenthal <wiesenthal@univention.de>  Mon, 12 Nov 2012 19:52:36 +0100
12
 -- Dirk Wiesenthal <wiesenthal@univention.de>  Mon, 12 Nov 2012 19:52:36 +0100
(-)a/branches/ucs-3.1/ucs/base/univention-system-setup/umc/python/setup/setup_script.py (-11 / +6 lines)
 Lines 44-52   translation.set_language(default_locale[0]) Link Here 
44
_ = translation.translate
44
_ = translation.translate
45
locale.setlocale(locale.LC_ALL, default_locale) # needed for external translation (e.g. apt)
45
locale.setlocale(locale.LC_ALL, default_locale) # needed for external translation (e.g. apt)
46
46
47
import univention.config_registry
47
from univention.config_registry import ConfigRegistry, handler_set
48
from util import PATH_SETUP_SCRIPTS, PATH_PROFILE
48
from util import PATH_SETUP_SCRIPTS, PATH_PROFILE
49
ucr = univention.config_registry.ConfigRegistry()
49
ucr = ConfigRegistry()
50
50
51
class SetupScript(object):
51
class SetupScript(object):
52
	'''Baseclass for all Python-based Setup-Scripts.
52
	'''Baseclass for all Python-based Setup-Scripts.
 Lines 193-199   class SetupScript(object): Link Here 
193
			# nothing to do
193
			# nothing to do
194
			return
194
			return
195
		self._ucr_changes[var_name] = (oldval, value)
195
		self._ucr_changes[var_name] = (oldval, value)
196
		ucr[var_name] = value
197
196
198
	def commit_ucr(self):
197
	def commit_ucr(self):
199
		'''Saves ucr variables previously
198
		'''Saves ucr variables previously
 Lines 203-217   class SetupScript(object): Link Here 
203
		not raise an exception*. You can
202
		not raise an exception*. You can
204
		call it manually if you need to
203
		call it manually if you need to
205
		do it (e.g. in down())'''
204
		do it (e.g. in down())'''
206
		ucr.save()
207
		ucr.load()
208
		if self._ucr_changes:
205
		if self._ucr_changes:
209
			handler = univention.config_registry.configHandlers()
206
			handler_set(['%s=%s' % (var_name, value) for var_name, (_, value) in self._ucr_changes.items()])
210
			handler.load()
207
			# reset (in case it is called multiple times in a script)
211
			handler(self._ucr_changes.keys(), (ucr, self._ucr_changes))
208
			self._ucr_changes.clear()
212
		# reset (in case it is called multiple
209
		ucr.load()
213
		# times in a script
214
		self._ucr_changes = {}
215
210
216
	def get_ucr_var(self, var_name):
211
	def get_ucr_var(self, var_name):
217
		'''Retrieve the value of var_name from ucr'''
212
		'''Retrieve the value of var_name from ucr'''
218
   Bug #15723: Shuffle UCR code
213
   Bug #15723: Shuffle UCR code
219
   
214
   
220
   Move some code in preparation to fix locking issue.
215
   Move some code in preparation to fix locking issue.
(-)a/branches/ucs-3.1/ucs/base/univention-config-registry/python/univention/config_registry/backend.py (-25 / +29 lines)
 Lines 248-256   class _ConfigRegistry(dict): Link Here 
248
		self.strict_encoding = False
248
		self.strict_encoding = False
249
		self.lock_file = None
249
		self.lock_file = None
250
250
251
	def __create_base_conf(self):
252
		"""Create sub registry file."""
253
		if not os.path.exists(self.file):
254
			try:
255
				reg_file = os.open(self.file, os.O_CREAT | os.O_RDONLY, 0644)
256
				os.close(reg_file)
257
			except EnvironmentError:
258
				msg = "E: file '%s' does not exist and could not be created"
259
				print >> sys.stderr, msg % (self.file,)
260
				exception_occured()
261
262
	def __load_file(self, reg_file):
263
		"""Load sub registry from opened file."""
264
		self.clear()
265
		for line in reg_file.readlines():
266
			line = re.sub(r'^[^:]*#.*$', "", line)
267
			if line == '':
268
				continue
269
			if line.find(': ') == -1:
270
				continue
271
272
			key, value = line.split(': ', 1)
273
			value = value.strip()
274
			if len(value) == 0:  # if variable was set without an value
275
				value = ''
276
277
			self[key] = value
278
251
	def load(self):
279
	def load(self):
252
		"""Load sub registry from file."""
280
		"""Load sub registry from file."""
253
		self.clear()
254
		import_failed = False
281
		import_failed = False
255
		try:
282
		try:
256
			reg_file = open(self.file, 'r')
283
			reg_file = open(self.file, 'r')
 Lines 267-301   class _ConfigRegistry(dict): Link Here 
267
				return
294
				return
268
295
269
		reg_file.seek(0)
296
		reg_file.seek(0)
270
		for line in reg_file.readlines():
297
		self.__load_file(reg_file)
271
			line = re.sub(r'^[^:]*#.*$', "", line)
272
			if line == '':
273
				continue
274
			if line.find(': ') == -1:
275
				continue
276
277
			key, value = line.split(': ', 1)
278
			value = value.strip()
279
			if len(value) == 0:  # if variable was set without an value
280
				value = ''
281
282
			self[key] = value
283
		reg_file.close()
298
		reg_file.close()
284
299
285
		if import_failed:
300
		if import_failed:
286
			self.__save_file(self.file)
301
			self.__save_file(self.file)
287
302
288
	def __create_base_conf(self):
289
		"""Create sub registry file."""
290
		if not os.path.exists(self.file):
291
			try:
292
				reg_file = os.open(self.file, os.O_CREAT | os.O_RDONLY, 0644)
293
				os.close(reg_file)
294
			except EnvironmentError:
295
				msg = "E: file '%s' does not exist and could not be created"
296
				print >> sys.stderr, msg % (self.file,)
297
				exception_occured()
298
299
	def __save_file(self, filename):
303
	def __save_file(self, filename):
300
		"""Save sub registry to file."""
304
		"""Save sub registry to file."""
301
		try:
305
		try:
(-)a/branches/ucs-3.1/ucs/base/univention-config-registry/python/univention/config_registry/frontend.py (-7 / +4 lines)
 Lines 139-145   def handler_set(args, opts=dict(), quiet=False): Link Here 
139
	reg.lock()
139
	reg.lock()
140
	try:
140
	try:
141
		reg.load()
141
		reg.load()
142
143
		changed = {}
142
		changed = {}
144
		for arg in args:
143
		for arg in args:
145
			sep_set = arg.find('=')  # set
144
			sep_set = arg.find('=')  # set
 Lines 179-189   def handler_set(args, opts=dict(), quiet=False): Link Here 
179
						print 'Not updating %s' % key
178
						print 'Not updating %s' % key
180
					else:
179
					else:
181
						print 'Not setting %s' % key
180
						print 'Not setting %s' % key
182
183
		reg.save()
181
		reg.save()
184
	finally:
182
	finally:
185
		reg.unlock()
183
		reg.unlock()
186
187
	handlers(changed.keys(), (reg, changed))
184
	handlers(changed.keys(), (reg, changed))
188
185
189
186
 Lines 191-196   def handler_unset(args, opts=dict()): Link Here 
191
	"""
188
	"""
192
	Unset config registry variables in args.
189
	Unset config registry variables in args.
193
	"""
190
	"""
191
	handlers = ConfigHandlers()
192
	handlers.load()
193
194
	current_scope = ConfigRegistry.NORMAL
194
	current_scope = ConfigRegistry.NORMAL
195
	reg = None
195
	reg = None
196
	if opts.get('ldap-policy', False):
196
	if opts.get('ldap-policy', False):
 Lines 204-216   def handler_unset(args, opts=dict()): Link Here 
204
		reg = ConfigRegistry(write_registry=current_scope)
204
		reg = ConfigRegistry(write_registry=current_scope)
205
	else:
205
	else:
206
		reg = ConfigRegistry()
206
		reg = ConfigRegistry()
207
207
	reg.lock()
208
	reg.lock()
208
	try:
209
	try:
209
		reg.load()
210
		reg.load()
210
211
		handlers = ConfigHandlers()
212
		handlers.load()
213
214
		changed = {}
211
		changed = {}
215
		for arg in args:
212
		for arg in args:
216
			if reg.has_key(arg, write_registry_only=True):
213
			if reg.has_key(arg, write_registry_only=True):
217
   Bug #15723: direct _write_registry usage
214
   Bug #15723: direct _write_registry usage
218
   
215
   
219
   Make _write_registry a direct reference to the writeable ConfigRegistry
216
   Make _write_registry a direct reference to the writeable ConfigRegistry
220
   instead of of being an index info _registry[]
217
   instead of of being an index info _registry[]
(-)a/branches/ucs-3.1/ucs/base/univention-config-registry/python/univention/config_registry/backend.py (-16 / +7 lines)
 Lines 75-84   class ConfigRegistry(dict): Link Here 
75
	def __init__(self, filename=None, write_registry=NORMAL):
75
	def __init__(self, filename=None, write_registry=NORMAL):
76
		dict.__init__(self)
76
		dict.__init__(self)
77
		self.file = os.getenv('UNIVENTION_BASECONF') or filename or None
77
		self.file = os.getenv('UNIVENTION_BASECONF') or filename or None
78
		if self.file:
79
			self._write_registry = ConfigRegistry.CUSTOM
80
		else:
81
			self._write_registry = write_registry
82
		self._registry = [None] * ConfigRegistry.MAX
78
		self._registry = [None] * ConfigRegistry.MAX
83
		for reg in range(ConfigRegistry.MAX):
79
		for reg in range(ConfigRegistry.MAX):
84
			if self.file and reg != ConfigRegistry.CUSTOM:
80
			if self.file and reg != ConfigRegistry.CUSTOM:
 Lines 87-92   class ConfigRegistry(dict): Link Here 
87
				self._registry[reg] = {}
83
				self._registry[reg] = {}
88
			else:
84
			else:
89
				self._registry[reg] = self._create_registry(reg)
85
				self._registry[reg] = self._create_registry(reg)
86
		self._write_registry = self._registry[ConfigRegistry.CUSTOM if self.file else write_registry]
90
87
91
	def _create_registry(self, reg):
88
	def _create_registry(self, reg):
92
		"""Create internal sub registry."""
89
		"""Create internal sub registry."""
 Lines 109-131   class ConfigRegistry(dict): Link Here 
109
106
110
	def save(self):
107
	def save(self):
111
		"""Save registry to file."""
108
		"""Save registry to file."""
112
		registry = self._registry[self._write_registry]
109
		self._write_registry.save()
113
		registry.save()
114
110
115
	def lock(self):
111
	def lock(self):
116
		"""Lock registry file."""
112
		"""Lock registry file."""
117
		registry = self._registry[self._write_registry]
113
		self._write_registry.lock()
118
		registry.lock()
119
114
120
	def unlock(self):
115
	def unlock(self):
121
		"""Un-lock registry file."""
116
		"""Un-lock registry file."""
122
		registry = self._registry[self._write_registry]
117
		self._write_registry.unlock()
123
		registry.unlock()
124
118
125
	def __delitem__(self, key):
119
	def __delitem__(self, key):
126
		"""Delete registry key."""
120
		"""Delete registry key."""
127
		registry = self._registry[self._write_registry]
121
		del self._write_registry[key]
128
		del registry[key]
129
122
130
	def __getitem__(self, key):
123
	def __getitem__(self, key):
131
		"""Return registry value."""
124
		"""Return registry value."""
 Lines 133-140   class ConfigRegistry(dict): Link Here 
133
126
134
	def __setitem__(self, key, value):
127
	def __setitem__(self, key, value):
135
		"""Set registry value."""
128
		"""Set registry value."""
136
		registry = self._registry[self._write_registry]
129
		self._write_registry[key] = value
137
		registry[key] = value
138
130
139
	def __contains__(self, key):
131
	def __contains__(self, key):
140
		"""Check if registry key is set."""
132
		"""Check if registry key is set."""
 Lines 181-188   class ConfigRegistry(dict): Link Here 
181
	def has_key(self, key, write_registry_only=False):
173
	def has_key(self, key, write_registry_only=False):
182
		"""Check if registry key is set (DEPRECATED)."""
174
		"""Check if registry key is set (DEPRECATED)."""
183
		if write_registry_only:
175
		if write_registry_only:
184
			registry = self._registry[self._write_registry]
176
			return key in self._write_registry
185
			return key in registry
186
		else:
177
		else:
187
			return key in self
178
			return key in self
188
179
189
   Bug #15723: Convert dict to array
180
   Bug #15723: Convert dict to array
190
   
181
   
191
   _registry is only indexed by number, so use more efficient array.
182
   _registry is only indexed by number, so use more efficient array.
(-)a/branches/ucs-3.1/ucs/base/univention-config-registry/python/univention/config_registry/backend.py (-3 / +3 lines)
 Lines 79-85   class ConfigRegistry(dict): Link Here 
79
			self._write_registry = ConfigRegistry.CUSTOM
79
			self._write_registry = ConfigRegistry.CUSTOM
80
		else:
80
		else:
81
			self._write_registry = write_registry
81
			self._write_registry = write_registry
82
		self._registry = {}
82
		self._registry = [None] * ConfigRegistry.MAX
83
		for reg in range(ConfigRegistry.MAX):
83
		for reg in range(ConfigRegistry.MAX):
84
			if self.file and reg != ConfigRegistry.CUSTOM:
84
			if self.file and reg != ConfigRegistry.CUSTOM:
85
				self._registry[reg] = {}
85
				self._registry[reg] = {}
 Lines 99-109   class ConfigRegistry(dict): Link Here 
99
99
100
	def load(self):
100
	def load(self):
101
		"""Load registry from file."""
101
		"""Load registry from file."""
102
		for reg in self._registry.values():
102
		for reg in self._registry:
103
			if isinstance(reg, _ConfigRegistry):
103
			if isinstance(reg, _ConfigRegistry):
104
				reg.load()
104
				reg.load()
105
		strict = self.is_true('ucr/encoding/strict')
105
		strict = self.is_true('ucr/encoding/strict')
106
		for reg in self._registry.values():
106
		for reg in self._registry:
107
			if isinstance(reg, _ConfigRegistry):
107
			if isinstance(reg, _ConfigRegistry):
108
				reg.strict_encoding = strict
108
				reg.strict_encoding = strict
109
109
110
   Bug #15723: Fix file(name) variable
110
   Bug #15723: Fix file(name) variable
111
   
111
   
112
   file() is a Python build-in, so the test always evaluates to True.
112
   file() is a Python build-in, so the test always evaluates to True.
113
   Use right "filename" instead.
113
   Use right "filename" instead.
(-)a/branches/ucs-3.1/ucs/base/univention-config-registry/python/univention/config_registry/backend.py (-4 / +1 lines)
 Lines 247-256   class _ConfigRegistry(dict): Link Here 
247
	"""
247
	"""
248
	def __init__(self, filename=None):
248
	def __init__(self, filename=None):
249
		dict.__init__(self)
249
		dict.__init__(self)
250
		if file:
250
		self.file = filename or '/etc/univention/base.conf'
251
			self.file = filename
252
		else:
253
			self.file = '/etc/univention/base.conf'
254
		self.__create_base_conf()
251
		self.__create_base_conf()
255
		self.backup_file = self.file + '.bak'
252
		self.backup_file = self.file + '.bak'
256
		self.lock_filename = self.file + '.lock'
253
		self.lock_filename = self.file + '.lock'

Return to bug 15723