View | Details | Raw Unified | Return to bug 43286 | Differences between
and this patch

Collapse All | Expand All

(-)a/management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py (+51 lines)
 Lines 527-532   def _ldap_pre_remove(self): Link Here 
527
	def _ldap_post_remove(self):
527
	def _ldap_post_remove(self):
528
		pass
528
		pass
529
529
530
	def remove_value(self, key, value=None):
531
		"""Removes a specific value from the specified property.
532
			If this value is currently not set univention.admin.uexceptions.valueNotSet is raised.
533
			if value is None the whole values of this property gets removed.
534
		"""
535
		if not self.has_key(key):
536
			raise univention.admin.uexceptions.noProperty(key)
537
538
		if value is None:
539
			# remove all currently set values
540
			self[key] = [] if self.descriptions[key].multivalue else None
541
			return
542
543
		if not self.contains_value(key, value):
544
			raise univention.admin.uexceptions.valueNotSet(key, value)
545
546
		if not self.descriptions[key].multivalue:
547
			self[key] = value
548
			return
549
550
		current_values = list(self[key])
551
		for val in current_values[:]:
552
			if self.compare_value(key, value, val):
553
				current_values.remove(val)
554
		self[key] = current_values
555
556
	def contains_value(self, key, value):
557
		if self.descriptions[key].multivalue and any(self.compare_value(key, value, val) for val in self[key]):
558
			return True
559
		if not self.descriptions[key].multivalue and self.compare_value(key, value, self[key]):
560
			return True
561
		return False
562
563
	def compare_value(self, key, a, b):
564
		return self.descriptions[key].syntax.compare(a, b)
565
566
	def append_value(self, key, value):
567
		if not self.has_key(key):
568
			raise univention.admin.uexceptions.noProperty(key)
569
570
		if self.contains_value(key, value):
571
			raise univention.admin.uexceptions.valueAlreadySet(key, value)
572
573
		if not self.descriptions[key].multivalue:
574
			self[key] = value
575
			return
576
577
		current_values = self[key]
578
		current_values.append(value)
579
		self[key] = current_values
580
530
581
531
def _not_implemented_method(attr):
582
def _not_implemented_method(attr):
532
	def _not_implemented_error(self, *args, **kwargs):
583
	def _not_implemented_error(self, *args, **kwargs):
(-)a/management/univention-directory-manager-modules/modules/univention/admin/syntax.py (-3 / +13 lines)
 Lines 138-143   def type(cls): Link Here 
138
	def tostring(self, text):
138
	def tostring(self, text):
139
		return text
139
		return text
140
140
141
	@classmethod
142
	def compare(cls, a, b):
143
		return a == b
144
141
145
142
class simple(ISyntax):
146
class simple(ISyntax):
143
	regex = None
147
	regex = None
 Lines 2055-2071   class soundModule(select): Link Here 
2055
	]
2059
	]
2056
2060
2057
2061
2058
class GroupDN(UDM_Objects):
2062
class _DNCompare(UDM_Objects):
2063
	@classmethod
2064
	def compare(cls, a, b):
2065
		return univention.admin.uldap.DN(a) == univention.admin.uldap.DN(b)
2066
2067
2068
class GroupDN(_DNCompare):
2059
	udm_modules = ('groups/group', )
2069
	udm_modules = ('groups/group', )
2060
	use_objects = False
2070
	use_objects = False
2061
2071
2062
2072
2063
class UserDN(UDM_Objects):
2073
class UserDN(_DNCompare):
2064
	udm_modules = ('users/user', )
2074
	udm_modules = ('users/user', )
2065
	use_objects = False
2075
	use_objects = False
2066
2076
2067
2077
2068
class HostDN(UDM_Objects):
2078
class HostDN(_DNCompare):
2069
	udm_modules = ('computers/computer', )
2079
	udm_modules = ('computers/computer', )
2070
	udm_filter = '!(univentionObjectFlag=docker)'
2080
	udm_filter = '!(univentionObjectFlag=docker)'
2071
2081
(-)a/management/univention-directory-manager-modules/modules/univention/admin/uexceptions.py (+8 lines)
 Lines 97-102   class valueMismatch(valueError): Link Here 
97
	message = _('Values do not match.')
97
	message = _('Values do not match.')
98
98
99
99
100
class valueNotSet(valueError):
101
	message = _('The value is not set.')
102
103
104
class valueAlreadySet(valueError):
105
	message = _('The value is already set.')
106
107
100
class noLock(base):
108
class noLock(base):
101
	message = _('Could not acquire lock.')
109
	message = _('Could not acquire lock.')
102
110
(-)a/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-138 / +73 lines)
 Lines 254-346   def _2utf8(text): Link Here 
254
def object_input(module, object, input, append=None, remove=None):
254
def object_input(module, object, input, append=None, remove=None):
255
	out = []
255
	out = []
256
	if append:
256
	if append:
257
		for key, value in append.items():
257
		for key, values in append.items():
258
			if module.property_descriptions[key].syntax.name == 'file':
258
			if module.property_descriptions[key].syntax.name == 'file':
259
				if os.path.exists(value):
259
				if os.path.exists(values):
260
					fh = open(value, 'r')
260
					fh = open(values, 'r')
261
					content = ''
261
					content = ''
262
					for line in fh.readlines():
262
					for line in fh.readlines():
263
						content += line
263
						content += line
264
					object[key] = content
264
					object[key] = content
265
					fh.close()
265
					fh.close()
266
				else:
266
				else:
267
					out.append('WARNING: file not found: %s' % value)
267
					out.append('WARNING: file not found: %s' % values)
268
				continue
268
269
269
			elif univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
270
				for i in range(0, len(value)):
271
					test_val = value[i].split('"')
272
					if test_val[0] and test_val[0] == value[i]:
273
						val = value[i].split(' ')
274
					else:
275
						val = []
276
						for j in test_val:
277
							if j and j.rstrip().lstrip():
278
								val.append(j.rstrip().lstrip())
279
280
					if not object.has_key(key):
281
						object[key] = []
282
					if val in object[key]:
283
						out.append('WARNING: cannot append %s to %s, value exists' % (val, key))
284
					elif object[key] == [''] or object[key] == []:
285
						object[key] = [val]
286
					else:
287
						object[key].append(val)
288
			else:
289
				for val in value:
290
					if val in object[key]:
291
						out.append('WARNING: cannot append %s to %s, value exists' % (val, key))
292
					elif object[key] == [''] or object[key] == []:
293
						object[key] = [val]
294
					else:
295
						try:
296
							tmp = list(object[key])
297
							tmp.append(val)
298
							object[key] = list(tmp)
299
						except univention.admin.uexceptions.valueInvalidSyntax, errmsg:
300
							out.append('E: Invalid Syntax: %s' % str(errmsg))
301
	if remove:
302
		for key, value in remove.items():
303
			if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
270
			if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
304
				if value:
271
				values = _parse_complex_syntax_input(values)
305
					for i in range(0, len(value)):
306
						test_val = value[i].split('"')
307
						if test_val[0] and test_val[0] == value[i]:
308
							val = value[i].split(' ')
309
						else:
310
							val = []
311
							out.append('test_val=%s' % test_val)
312
							for j in test_val:
313
								if j and j.rstrip().lstrip():
314
									val.append(j.rstrip().lstrip())
315
272
316
							for j in range(0, len(val)):
273
			for value in values:
317
								val[j] = '"%s"' % val[j]
274
				try:
318
275
					object.append_value(key, value)
319
						if val and val in object[key]:
276
				except univention.admin.uexceptions.noProperty as exc:
320
							object[key].remove(val)
277
					out.append("WARNING: No attribute with name %s in this module, value not appended." % (key,))
321
						else:
278
				except univention.admin.uexceptions.valueNotSet as exc:
322
							out.append("WARNING: cannot remove %s from %s, value does not exist" % (val, key))
279
					out.append("WARNING: cannot append %s to %s: %s" % (value, key, exc))
323
				else:
280
				except univention.admin.uexceptions.valueInvalidSyntax as exc:
324
					object[key] = []
281
					out.append('E: Invalid Syntax: %s' % (exc,))
282
	if remove:
283
		for key, values in remove.items():
284
			if not values:
285
				values = [None]  # remove the whole property
325
286
326
			else:
287
			if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
327
				current_values = [object[key]] if isinstance(object[key], basestring) else list(object[key])
288
				values = _parse_complex_syntax_input(values)
328
				if value is None:
329
					current_values = []
330
				else:
331
					vallist = [value] if isinstance(value, basestring) else value
332
289
333
					for val in vallist:
290
			for value in values:
334
						if val in current_values:
291
				try:
335
							current_values.remove(val)
292
					object.remove_value(key, value)
336
						else:
293
				except univention.admin.uexceptions.noProperty as exc:
337
							out.append("WARNING: cannot remove %s from %s, value does not exist" % (val, key))
294
					out.append("WARNING: No attribute with name %s in this module, value not removed." % (key,))
338
				if not module.property_descriptions[key].multivalue:
295
				except univention.admin.uexceptions.valueNotSet as exc:
339
					try:
296
					out.append("WARNING: cannot remove %s from %s: %s" % (value, key, exc))
340
						current_values = current_values[0]
341
					except IndexError:
342
						current_values = None
343
				object[key] = current_values
344
	if input:
297
	if input:
345
		for key, value in input.items():
298
		for key, value in input.items():
346
			if module.property_descriptions[key].syntax.name == 'binaryfile':
299
			if module.property_descriptions[key].syntax.name == 'binaryfile':
 Lines 360-377   def object_input(module, object, input, append=None, remove=None): Link Here 
360
					out.append('WARNING: file not found: %s' % value)
313
					out.append('WARNING: file not found: %s' % value)
361
314
362
			elif univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
315
			elif univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
363
				if isinstance(value, list):
316
				val = _parse_complex_syntax_input(value)
364
					for i in range(0, len(value)):
365
						test_val = value[i].split('"')
366
						if test_val[0] and test_val[0] == value[i]:
367
							val = value[i].split(' ')
368
						else:
369
							val = []
370
							for j in test_val:
371
								if j and j.rstrip().lstrip():
372
									val.append(j.rstrip().lstrip())
373
				else:
374
					val = value.split(' ')
375
				if module.property_descriptions[key].multivalue:
317
				if module.property_descriptions[key].multivalue:
376
					object[key] = [val]
318
					object[key] = [val]
377
				else:
319
				else:
 Lines 386-391   def object_input(module, object, input, append=None, remove=None): Link Here 
386
	return out
328
	return out
387
329
388
330
331
def _parse_complex_syntax_input(values):
332
	parsed_values = []
333
	for value in values:
334
		if '"' not in value:
335
			value = value.split(' ')
336
		else:
337
			value = ['"%s"' % (x.strip(),) for x in value.split('"') if x.strip()]
338
		parsed_values.append(value)
339
	return parsed_values
340
341
342
389
def list_available_modules(o=[]):
343
def list_available_modules(o=[]):
390
344
391
	o.append("Available Modules are:")
345
	o.append("Available Modules are:")
 Lines 629-696   def _doit(arglist): Link Here 
629
583
630
	for opt, val in opts:
584
	for opt, val in opts:
631
		if opt == '--set':
585
		if opt == '--set':
632
			pos = val.find('=')
586
			try:
633
			name = val[:pos]
587
				name, value = val.split('=', 1)
634
			value = _2utf8(val[pos + 1:])
588
			except ValueError:
589
				name, value = val, ''
590
			value = _2utf8(value)
635
591
636
			was_set = 0
637
			for mod, (properties, options) in information.items():
592
			for mod, (properties, options) in information.items():
638
				if properties.has_key(name):
593
				if name not in properties:
639
					if properties[name].multivalue:
594
					out.append("WARNING: No attribute with name '%s' in this module, value not set." % name)
640
						if not input.has_key(name):
595
					continue
641
							input[name] = []
596
				if properties[name].multivalue:
642
							was_set = 1
597
					input.setdefault(name, [])
643
						if value:
598
					if value:
644
							input[name].append(value)
599
						input[name].append(value)
645
							was_set = 1
600
				else:
646
					else:
601
					input[name] = value
647
						input[name] = value
648
						was_set = 1
649
650
			if not was_set:
651
				out.append("WARNING: No attribute with name '%s' in this module, value not set." % name)
652
		elif opt == '--append':
602
		elif opt == '--append':
653
			pos = val.find('=')
603
			try:
654
			name = val[:pos]
604
				name, value = val.split('=', 1)
655
			value = _2utf8(val[pos + 1:])
605
			except ValueError:
656
			was_set = 0
606
				name, value = val, ''
607
			value = _2utf8(value)
657
			for mod, (properties, options) in information.items():
608
			for mod, (properties, options) in information.items():
658
				if properties.has_key(name):
609
				try:
610
					properties[name]
611
				except KeyError:
612
					pass
613
				else:
659
					if properties[name].multivalue:
614
					if properties[name].multivalue:
660
						if not append.has_key(name):
615
						append.setdefault(name, [])
661
							append[name] = []
662
						if value:
616
						if value:
663
							append[name].append(value)
617
							append[name].append(value)
664
							was_set = 1
618
					else:  # hmm. this should be illegal ^^
665
					else:
666
						append[name] = value
619
						append[name] = value
667
						was_set = 1
668
			if not was_set:
669
				out.append("WARNING: No attribute with name %s in this module, value not appended." % name)
670
671
		elif opt == '--remove':
620
		elif opt == '--remove':
672
			pos = val.find('=')
621
			try:
673
			if pos == -1:
622
				name, value = val.split('=', 1)
623
			except ValueError:
674
				name = val
624
				name = val
675
				value = None
625
				remove[name] = None
676
			else:
626
			else:
677
				name = val[:pos]
627
				value = _2utf8(value)
678
				value = _2utf8(val[pos + 1:])
628
				remove.setdefault(name, []).append(value)
679
			was_set = False
680
			for mod, (properties, options) in information.items():
681
				if properties.has_key(name):
682
					was_set = True
683
					if properties[name].multivalue:
684
						if value is None:
685
							remove[name] = value
686
						elif value:
687
							remove.setdefault(name, [])
688
							if remove[name] is not None:
689
								remove[name].append(value)
690
					else:
691
						remove[name] = value
692
			if not was_set:
693
				out.append("WARNING: No attribute with name %s in this module, value not removed." % name)
694
		elif opt == '--remove_referring':
629
		elif opt == '--remove_referring':
695
			remove_referring = 1
630
			remove_referring = 1
696
		elif opt == '--recursive':
631
		elif opt == '--recursive':

Return to bug 43286