Lines 263-316
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
263 |
out.append('WARNING: file not found: %s' % values) |
263 |
out.append('WARNING: file not found: %s' % values) |
264 |
else: |
264 |
else: |
265 |
values = [module.property_descriptions[key].syntax.parse_command_line(x) for x in values] |
265 |
values = [module.property_descriptions[key].syntax.parse_command_line(x) for x in values] |
266 |
current_values = list(object[key] or []) |
266 |
for value in values: |
267 |
if current_values == ['']: |
|
|
268 |
current_values = [] |
269 |
|
270 |
for val in values: |
271 |
if val in current_values: |
272 |
out.append('WARNING: cannot append %s to %s, value exists' % (val, key)) |
273 |
else: |
274 |
current_values.append(val) |
275 |
|
276 |
if not module.property_descriptions[key].multivalue: |
277 |
try: |
267 |
try: |
278 |
current_values = current_values[-1] |
268 |
object.append_value(key, value) |
279 |
except IndexError: |
269 |
except univention.admin.uexceptions.noProperty: |
280 |
current_values = None |
270 |
raise OperationFailed(out, "WARNING: No attribute with name %s in this module, value not appended." % (key,)) |
281 |
|
271 |
except univention.admin.uexceptions.valueNotSet as exc: |
282 |
try: |
272 |
raise OperationFailed(out, "WARNING: cannot append %s to %s: %s" % (value, key, exc)) |
283 |
object[key] = current_values |
273 |
except univention.admin.uexceptions.valueInvalidSyntax as errmsg: |
284 |
except univention.admin.uexceptions.valueInvalidSyntax as errmsg: |
274 |
raise OperationFailed(out, 'E: Invalid Syntax: %s' % (errmsg,)) |
285 |
raise OperationFailed(out, 'E: Invalid Syntax: %s' % (errmsg,)) |
|
|
286 |
|
275 |
|
287 |
if remove: |
276 |
if remove: |
288 |
for key, values in remove.items(): |
277 |
for key, values in remove.items(): |
289 |
current_values = [object[key]] if not module.property_descriptions[key].multivalue else list(object[key]) |
278 |
try: |
290 |
if values is None: |
279 |
if values is None: |
291 |
current_values = [] |
280 |
object.remove_value(key, values) |
292 |
else: |
281 |
continue |
293 |
vallist = [values] if isinstance(values, six.string_types) else values |
282 |
for value in values: |
294 |
vallist = [module.property_descriptions[key].syntax.parse_command_line(x) for x in vallist] |
283 |
value = module.property_descriptions[key].syntax.parse_command_line(value) |
295 |
|
284 |
#try: # TODO: remove?! move into normalize() |
296 |
for val in vallist: |
285 |
# value = module.property_descriptions[key].syntax.parse(value) |
297 |
try: |
286 |
#except (univention.admin.uexceptions.valueInvalidSyntax, univention.admin.uexceptions.valueError): |
298 |
normalized_val = module.property_descriptions[key].syntax.parse(val) |
287 |
# pass |
299 |
except (univention.admin.uexceptions.valueInvalidSyntax, univention.admin.uexceptions.valueError): |
288 |
object.remove_value(key, value) |
300 |
normalized_val = None |
289 |
except univention.admin.uexceptions.noProperty: |
301 |
|
290 |
out.append("WARNING: No attribute with name %s in this module, value not removed." % (key,)) |
302 |
if val in current_values: |
291 |
except univention.admin.uexceptions.valueNotSet as exc: |
303 |
current_values.remove(val) |
292 |
out.append("WARNING: cannot remove %s from %s: %s" % (value, key, exc)) |
304 |
elif normalized_val is not None and normalized_val in current_values: |
|
|
305 |
current_values.remove(normalized_val) |
306 |
else: |
307 |
out.append("WARNING: cannot remove %s from %s, value does not exist" % (val, key)) |
308 |
if not module.property_descriptions[key].multivalue: |
309 |
try: |
310 |
current_values = current_values[0] |
311 |
except IndexError: |
312 |
current_values = None |
313 |
object[key] = current_values |
314 |
|
293 |
|
315 |
if input: |
294 |
if input: |
316 |
for key, value in input.items(): |
295 |
for key, value in input.items(): |