This function finds the effective host list, given a primary host and a list of secondary hosts. Here's the interface:
# - - - f i n d H o s t L i s t - - -
def findHostList ( priHost, secHostList ):
"""Derive the effective host list.
[ (priHost is the primary host as a string) and
(secHostList is a list of secondary host names, each
possibly with a trailing comma) ->
return the effective host list as a list of strings ]
"""
There is a lengthy discussion of the derivation of the
effective host list in the specification. The present function was not
in the original design; it was broken out of the
scanAccessGroup() function
because there was just too much logic in that function's
third prime.
The first case we eliminate is the case where secHostList contains either just "-" or an empty string. In that case,
the effective host list contains only the primary host.
#-- 1 --
if len(secHostList) == 0:
return [ priHost ]
else:
firstSec = secHostList[0]
Next we eliminate the cases where the first secondary
host is "-" or an empty string.
In those cases, we again return a list containing just
the primary host.
#-- 2 --
if ( ( len ( firstSec ) == 0 ) or
( firstSec == "-" ) ):
return [ priHost ]
At this point we have at least one secondary host. The result is this list, with any trailing commas removed from the elements.
#-- 3 --
hostList = []
#-- 4 --
# [ hostList +:= a list of the elements of secHostList with any
# trailing commas removed ]
for secHost in secHostList:
if secHost.endswith(","):
hostList.append ( secHost[:-1] )
else:
hostList.append ( secHost )
#-- 5 --
return hostList
What if one of the elements in secHostList is the empty string? The logic
above that strips trailing commas is carefully
constructed to work with empty strings. The Python
expressions "".endswith(",") returns False, and the expression
""[:-1] returns
the empty string.