提交 858428dd 编写于 作者: K Kalen Krempely 提交者: Bhuvnesh

remove dead code appendNewEntriesToHbaFile()

上级 57eda1bf
......@@ -348,50 +348,6 @@ def parseKeyColonValueLines(str):
def sortedDictByKey(di):
return [ (k,di[k]) for k in sorted(di.keys())]
def appendNewEntriesToHbaFile(fileName, segments):
"""
Will raise Exception if there is a problem updating the hba file
"""
try:
#
# Get the list of lines that already exist...we won't write those again
#
# Replace runs of whitespace with single space to improve deduping
#
def lineToCanonical(s):
s = re.sub("\s", " ", s) # first reduce whitespace runs to single space
s = re.sub(" $", "", s) # remove trailing space
s = re.sub("^ ", "", s) # remove leading space
return s
existingLineMap = {}
for line in readAllLinesFromFile(fileName):
existingLineMap[lineToCanonical(line)] = True
fp = open(fileName, 'a')
try:
for newSeg in segments:
address = newSeg.getSegmentAddress()
addrinfo = socket.getaddrinfo(address, None)
ipaddrlist = list(set([ (ai[0], ai[4][0]) for ai in addrinfo]))
haveWrittenCommentHeader = False
for addr in ipaddrlist:
newLine = 'host\tall\tall\t%s/%s\ttrust' % (addr[1], '32' if addr[0] == socket.AF_INET else '128')
newLineCanonical = lineToCanonical(newLine)
if newLineCanonical not in existingLineMap:
if not haveWrittenCommentHeader:
fp.write('# %s\n' % address)
haveWrittenCommentHeader = True
fp.write(newLine)
fp.write('\n')
existingLineMap[newLineCanonical] = True
finally:
fp.close()
except IOError as msg:
raise Exception('Failed to open %s' % fileName)
except Exception as msg:
raise Exception('Failed to add new segments to template %s' % fileName)
class TableLogger:
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册