Cleanup of /etc/hosts ordering and pep8/pylint adjustments.
Fix how the comparison of a fqdn and its aliases was done via sorting instead of existence checking which is the better way to check if a alias already exists as well as cleanup the new files pep8/pylint issues.
This commit is contained in:
parent
63a5834c54
commit
c876617723
@ -189,15 +189,20 @@ class Distro(object):
|
||||
else:
|
||||
need_change = True
|
||||
for entry in prev_info:
|
||||
if sorted(entry) == sorted([fqdn, hostname]):
|
||||
# Exists already, leave it be
|
||||
need_change = False
|
||||
break
|
||||
entry_fqdn = None
|
||||
entry_aliases = []
|
||||
if len(entry) >= 1:
|
||||
entry_fqdn = entry[0]
|
||||
if len(entry) >= 2:
|
||||
entry_aliases = entry[1:]
|
||||
if entry_fqdn is not None and entry_fqdn == fqdn:
|
||||
if hostname in entry_aliases:
|
||||
# Exists already, leave it be
|
||||
need_change = False
|
||||
if need_change:
|
||||
# Doesn't exist, change the first
|
||||
# entry to be this entry
|
||||
# Doesn't exist, add that entry in...
|
||||
new_entries = list(prev_info)
|
||||
new_entries[0] = [fqdn, hostname]
|
||||
new_entries.append([fqdn, hostname])
|
||||
eh.del_entries(local_ip)
|
||||
for entry in new_entries:
|
||||
if len(entry) == 1:
|
||||
|
@ -16,6 +16,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
def chop_comment(text, comment_chars):
|
||||
comment_locations = [text.find(c) for c in comment_chars]
|
||||
comment_locations = [c for c in comment_locations if c != -1]
|
||||
|
@ -86,5 +86,3 @@ class HostnameConf(object):
|
||||
raise IOError("Multiple hostnames (%s) found!"
|
||||
% (hostnames_found))
|
||||
return entries
|
||||
|
||||
|
||||
|
@ -127,7 +127,7 @@ class ResolvConf(object):
|
||||
# Hard restriction on only 6 search domains
|
||||
raise ValueError(("Adding %r would go beyond the "
|
||||
"'6' maximum search domains") % (search_domain))
|
||||
s_list = " ".join(new_sds)
|
||||
s_list = " ".join(new_sds)
|
||||
if len(s_list) > 256:
|
||||
# Some hard limit on 256 chars total
|
||||
raise ValueError(("Adding %r would go beyond the "
|
||||
@ -167,5 +167,3 @@ class ResolvConf(object):
|
||||
raise IOError("Unexpected resolv.conf option %s" % (cfg_opt))
|
||||
entries.append(("option", [cfg_opt, cfg_values, tail]))
|
||||
return entries
|
||||
|
||||
|
||||
|
@ -40,7 +40,7 @@ SHELL_VAR_REGEXES = [
|
||||
# Things like $?, $0, $-, $@
|
||||
re.compile(r"\$[0-9#\?\-@\*]"),
|
||||
# Things like ${blah:1} - but this one
|
||||
# gets very complex so just try the
|
||||
# gets very complex so just try the
|
||||
# simple path
|
||||
re.compile(r"\$\{.+\}"),
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user