|
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:") |
|
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': |