From 5d1ca46ea79d5a70362248b06dd4587518f78150 Mon Sep 17 00:00:00 2001 From: John Dennis Date: Tue, 27 Nov 2007 16:16:10 -0500 Subject: do a better job of handling attribute deletion --- ipa-python/ipautil.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'ipa-python/ipautil.py') diff --git a/ipa-python/ipautil.py b/ipa-python/ipautil.py index f8310ae44..8839e6cf2 100644 --- a/ipa-python/ipautil.py +++ b/ipa-python/ipautil.py @@ -25,7 +25,6 @@ import logging import subprocess import os import stat -import copy import readline import traceback from types import * @@ -481,7 +480,7 @@ class AttributeValueCompleter: c = AttributeValueCompleter(attrs, defaults) c.open() - mandatory_attrs_remaining = copy.copy(mandatory_attrs) + mandatory_attrs_remaining = mandatory_attrs[:] while True: if mandatory_attrs_remaining: @@ -652,10 +651,10 @@ class AttributeValueCompleter: except EOFError: return None, None - def get_pairs(self, prompt, mandatory_attrs=None, validate_callback=None, must_match=Trueo, value_required=True): + def get_pairs(self, prompt, mandatory_attrs=None, validate_callback=None, must_match=True, value_required=True): pairs = {} if mandatory_attrs: - mandatory_attrs_remaining = copy.copy(mandatory_attrs) + mandatory_attrs_remaining = mandatory_attrs[:] else: mandatory_attrs_remaining = [] @@ -714,9 +713,8 @@ class ItemCompleter: ''' - def __init__(self, items, must_match=True): + def __init__(self, items): self.items = items - self.must_match = must_match self.initial_input = None self.item_delims = ' \t,' self.split_re = re.compile('[%s]+' % self.item_delims) @@ -768,26 +766,25 @@ class ItemCompleter: items = self.split_re.split(self.line_buffer) for item in items[:]: if not item: items.remove(item) - if self.must_match: - for item in items[:]: - if item not in self.items: - print "ERROR: %s is not valid" % (item) - items.remove(item) return items except EOFError: return items - def get_items(self, prompt): + def get_items(self, prompt, must_match=True): items = [] print "Enter name [name ...]" - print "Press to accept, control-D terminates input" + print "Press to accept, blank line or control-D terminates input" print "Pressing auto completes name" print while True: new_items = self.read_input(prompt) - if new_items is None: break + if not new_items: break for item in new_items: + if must_match: + if item not in self.items: + print "ERROR: %s is not valid" % (item) + continue if item in items: continue items.append(item) -- cgit