Lines 299-346
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
299 |
except univention.admin.uexceptions.valueInvalidSyntax, errmsg: |
299 |
except univention.admin.uexceptions.valueInvalidSyntax, errmsg: |
300 |
out.append('E: Invalid Syntax: %s' % str(errmsg)) |
300 |
out.append('E: Invalid Syntax: %s' % str(errmsg)) |
301 |
if remove: |
301 |
if remove: |
302 |
for key, value in remove.items(): |
302 |
for key, values in remove.items(): |
303 |
if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex): |
303 |
if not values: |
304 |
if value: |
304 |
values = [None] # remove the whole property |
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 |
|
316 |
for j in range(0, len(val)): |
317 |
val[j] = '"%s"' % val[j] |
318 |
|
319 |
if val and val in object[key]: |
320 |
object[key].remove(val) |
321 |
else: |
322 |
out.append("WARNING: cannot remove %s from %s, value does not exist" % (val, key)) |
323 |
else: |
324 |
object[key] = [] |
325 |
|
305 |
|
326 |
else: |
306 |
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]) |
307 |
parsed_values = [] |
328 |
if value is None: |
308 |
for value in values: |
329 |
current_values = [] |
309 |
if '"' not in value: |
330 |
else: |
310 |
value = value.split(' ') |
331 |
vallist = [value] if isinstance(value, basestring) else value |
311 |
else: |
|
|
312 |
value = ['"%s"' % (x.strip(),) for x in value.split('"') if x.strip()] |
313 |
parsed_values.append(value) |
314 |
values = parsed_values |
332 |
|
315 |
|
333 |
for val in vallist: |
316 |
for value in values: |
334 |
if val in current_values: |
317 |
try: |
335 |
current_values.remove(val) |
318 |
object.remove_value(key, value) |
336 |
else: |
319 |
except univention.admin.uexceptions.valueNotSet as exc: |
337 |
out.append("WARNING: cannot remove %s from %s, value does not exist" % (val, key)) |
320 |
out.append("WARNING: cannot remove %s from %s: %s" % (value, key, exc)) |
338 |
if not module.property_descriptions[key].multivalue: |
|
|
339 |
try: |
340 |
current_values = current_values[0] |
341 |
except IndexError: |
342 |
current_values = None |
343 |
object[key] = current_values |
344 |
if input: |
321 |
if input: |
345 |
for key, value in input.items(): |
322 |
for key, value in input.items(): |
346 |
if module.property_descriptions[key].syntax.name == 'binaryfile': |
323 |
if module.property_descriptions[key].syntax.name == 'binaryfile': |
|
669 |
out.append("WARNING: No attribute with name %s in this module, value not appended." % name) |
646 |
out.append("WARNING: No attribute with name %s in this module, value not appended." % name) |
670 |
|
647 |
|
671 |
elif opt == '--remove': |
648 |
elif opt == '--remove': |
672 |
pos = val.find('=') |
649 |
try: |
673 |
if pos == -1: |
650 |
name, value = val.split('=', 1) |
|
|
651 |
except ValueError: |
674 |
name = val |
652 |
name = val |
675 |
value = None |
653 |
remove[name] = None |
676 |
else: |
654 |
else: |
677 |
name = val[:pos] |
655 |
value = _2utf8(value) |
678 |
value = _2utf8(val[pos + 1:]) |
656 |
remove.setdefault(name, []).append(value) |
679 |
was_set = False |
657 |
# was_set = False |
680 |
for mod, (properties, options) in information.items(): |
658 |
# for mod, (properties, options) in information.items(): |
681 |
if properties.has_key(name): |
659 |
# if properties.has_key(name): |
682 |
was_set = True |
660 |
# was_set = True |
683 |
if properties[name].multivalue: |
661 |
# if properties[name].multivalue: |
684 |
if value is None: |
662 |
# if value is None: |
685 |
remove[name] = value |
663 |
# remove[name] = value |
686 |
elif value: |
664 |
# elif value: |
687 |
remove.setdefault(name, []) |
665 |
# remove.setdefault(name, []) |
688 |
if remove[name] is not None: |
666 |
# if remove[name] is not None: |
689 |
remove[name].append(value) |
667 |
# remove[name].append(value) |
690 |
else: |
668 |
# else: |
691 |
remove[name] = value |
669 |
# remove[name] = value |
692 |
if not was_set: |
670 |
# if not was_set: |
693 |
out.append("WARNING: No attribute with name %s in this module, value not removed." % name) |
671 |
# out.append("WARNING: No attribute with name %s in this module, value not removed." % name) |
694 |
elif opt == '--remove_referring': |
672 |
elif opt == '--remove_referring': |
695 |
remove_referring = 1 |
673 |
remove_referring = 1 |
696 |
elif opt == '--recursive': |
674 |
elif opt == '--recursive': |