mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
add parse_items(), read_items_file()
move read_pairs_file() to ipautil
This commit is contained in:
@@ -91,7 +91,7 @@ def main():
|
|||||||
# Get pairs from a file or stdin
|
# Get pairs from a file or stdin
|
||||||
if options.pair_file:
|
if options.pair_file:
|
||||||
try:
|
try:
|
||||||
av = radius_util.read_pairs_file(options.pair_file)
|
av = ipautil.read_pairs_file(options.pair_file)
|
||||||
pairs.update(av)
|
pairs.update(av)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "ERROR, could not read pairs (%s)" % (e)
|
print "ERROR, could not read pairs (%s)" % (e)
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ def main():
|
|||||||
# Get pairs from a file or stdin
|
# Get pairs from a file or stdin
|
||||||
if options.pair_file:
|
if options.pair_file:
|
||||||
try:
|
try:
|
||||||
av = radius_util.read_pairs_file(options.pair_file)
|
av = ipautil.read_pairs_file(options.pair_file)
|
||||||
pairs.update(av)
|
pairs.update(av)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "ERROR, could not read pairs (%s)" % (e)
|
print "ERROR, could not read pairs (%s)" % (e)
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ def main():
|
|||||||
# Get pairs from a file or stdin
|
# Get pairs from a file or stdin
|
||||||
if options.pair_file:
|
if options.pair_file:
|
||||||
try:
|
try:
|
||||||
av = radius_util.read_pairs_file(options.pair_file)
|
av = ipautil.read_pairs_file(options.pair_file)
|
||||||
pairs.update(av)
|
pairs.update(av)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "ERROR, could not read pairs (%s)" % (e)
|
print "ERROR, could not read pairs (%s)" % (e)
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ def main():
|
|||||||
# Get pairs from a file or stdin
|
# Get pairs from a file or stdin
|
||||||
if options.pair_file:
|
if options.pair_file:
|
||||||
try:
|
try:
|
||||||
av = radius_util.read_pairs_file(options.pair_file)
|
av = ipautil.read_pairs_file(options.pair_file)
|
||||||
pairs.update(av)
|
pairs.update(av)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "ERROR, could not read pairs (%s)" % (e)
|
print "ERROR, could not read pairs (%s)" % (e)
|
||||||
|
|||||||
@@ -416,6 +416,39 @@ def parse_key_value_pairs(input):
|
|||||||
kv_dict[key] = value
|
kv_dict[key] = value
|
||||||
return kv_dict
|
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:
|
class AttributeValueCompleter:
|
||||||
'''
|
'''
|
||||||
Gets input from the user in the form "lhs operator rhs"
|
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)
|
readline.set_pre_input_hook(self.pre_input_hook)
|
||||||
self.line_buffer = raw_input(prompt).strip()
|
self.line_buffer = raw_input(prompt).strip()
|
||||||
items = self.split_re.split(self.line_buffer)
|
items = self.split_re.split(self.line_buffer)
|
||||||
print items
|
|
||||||
for item in items[:]:
|
for item in items[:]:
|
||||||
if not item: items.remove(item)
|
if not item: items.remove(item)
|
||||||
if self.must_match:
|
if self.must_match:
|
||||||
|
|||||||
@@ -59,8 +59,6 @@ __all__ = [
|
|||||||
'radius_profile_ldap_attr_to_radius_attr',
|
'radius_profile_ldap_attr_to_radius_attr',
|
||||||
'radius_profile_attr_to_ldap_attr',
|
'radius_profile_attr_to_ldap_attr',
|
||||||
|
|
||||||
'read_pairs_file',
|
|
||||||
|
|
||||||
'get_secret',
|
'get_secret',
|
||||||
'validate_ip_addr',
|
'validate_ip_addr',
|
||||||
'validate_secret',
|
'validate_secret',
|
||||||
@@ -240,19 +238,6 @@ def radius_profile_dn(uid, container, suffix):
|
|||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
comment_re = re.compile('#.*$', re.MULTILINE)
|
|
||||||
def read_pairs_file(filename):
|
|
||||||
if filename == '-':
|
|
||||||
fd = sys.stdin
|
|
||||||
else:
|
|
||||||
fd = open(filename)
|
|
||||||
data = fd.read()
|
|
||||||
data = comment_re.sub('', data) # kill comments
|
|
||||||
pairs = ipautil.parse_key_value_pairs(data)
|
|
||||||
if fd != sys.stdin: fd.close()
|
|
||||||
return pairs
|
|
||||||
|
|
||||||
|
|
||||||
def get_ldap_attr_translations():
|
def get_ldap_attr_translations():
|
||||||
comment_re = re.compile('#.*$')
|
comment_re = re.compile('#.*$')
|
||||||
radius_attr_to_ldap_attr = {}
|
radius_attr_to_ldap_attr = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user