summaryrefslogtreecommitdiffstats
path: root/ipa-python/ipautil.py
diff options
context:
space:
mode:
authorJohn Dennis <jdennis@redhat.com>2007-11-26 23:11:49 -0500
committerJohn Dennis <jdennis@redhat.com>2007-11-26 23:11:49 -0500
commit78b5987101c3d489c8397da05546d72e24aeea4c (patch)
tree114e96d43170c4f4c2139c44084615f099625b6a /ipa-python/ipautil.py
parentc5a43a01686ae23e5381bc3b3f4c590774b865f8 (diff)
downloadfreeipa-78b5987101c3d489c8397da05546d72e24aeea4c.tar.gz
freeipa-78b5987101c3d489c8397da05546d72e24aeea4c.tar.xz
freeipa-78b5987101c3d489c8397da05546d72e24aeea4c.zip
add parse_items(), read_items_file()
move read_pairs_file() to ipautil
Diffstat (limited to 'ipa-python/ipautil.py')
-rw-r--r--ipa-python/ipautil.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/ipa-python/ipautil.py b/ipa-python/ipautil.py
index b5fa9794c..f8310ae44 100644
--- a/ipa-python/ipautil.py
+++ b/ipa-python/ipautil.py
@@ -416,6 +416,39 @@ def parse_key_value_pairs(input):
kv_dict[key] = value
return kv_dict
+def parse_items(text):
+ '''Given text with items separated by whitespace or comma, return a list of those items'''
+ split_re = re.compile('[ ,\t\n]+')
+ items = split_re.split(text)
+ for item in items[:]:
+ if not item: items.remove(item)
+ return items
+
+def read_pairs_file(filename):
+ comment_re = re.compile('#.*$', re.MULTILINE)
+ if filename == '-':
+ fd = sys.stdin
+ else:
+ fd = open(filename)
+ text = fd.read()
+ text = comment_re.sub('', text) # kill comments
+ pairs = ipautil.parse_key_value_pairs(text)
+ if fd != sys.stdin: fd.close()
+ return pairs
+
+def read_items_file(filename):
+ comment_re = re.compile('#.*$', re.MULTILINE)
+ if filename == '-':
+ fd = sys.stdin
+ else:
+ fd = open(filename)
+ text = fd.read()
+ text = comment_re.sub('', text) # kill comments
+ items = ipautil.parse_items(text)
+ if fd != sys.stdin: fd.close()
+ return items
+
+
class AttributeValueCompleter:
'''
Gets input from the user in the form "lhs operator rhs"
@@ -733,7 +766,6 @@ class ItemCompleter:
readline.set_pre_input_hook(self.pre_input_hook)
self.line_buffer = raw_input(prompt).strip()
items = self.split_re.split(self.line_buffer)
- print items
for item in items[:]:
if not item: items.remove(item)
if self.must_match: