X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=bin%2Fdns-config;h=5e62668a69d828c16b208b2f8f1afdcbb688c640;hb=e45ff0a6db152273a3ce7159cc770bf58fdb5156;hp=fbf294bf34efaa80b330d258581bac0ea1e9d562;hpb=27ae61d51ba27a22a2e9048b90fe158dd3fac592;p=myplc.git diff --git a/bin/dns-config b/bin/dns-config index fbf294b..5e62668 100755 --- a/bin/dns-config +++ b/bin/dns-config @@ -7,9 +7,11 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # +# pylint: disable=c0111 +import sys +import os from plc_config import PLCConfiguration -import os, sys def writepid(prog): """ @@ -17,18 +19,16 @@ def writepid(prog): """ try: - pidfile = file("/var/run/%s.pid" % prog, "r") - pid = pidfile.readline().strip() - pidfile.close() + with open("/var/run/%s.pid" % prog, "r") as pidfile: + pid = pidfile.readline().strip() if os.path.isdir("/proc/" + pid): - print "Error: Another copy of %s is still running (%s)" % (prog, pid) + print("Error: Another copy of %s is still running (%s)" % (prog, pid)) sys.exit(1) except IOError: pass - pidfile = file("/var/run/%s.pid" % prog, "w") - pidfile.write(str(os.getpid())) - pidfile.close() + with open("/var/run/%s.pid" % prog, "w") as pidfile: + pidfile.write(str(os.getpid())) def removepid(prog): os.unlink("/var/run/%s.pid" % prog) @@ -40,9 +40,10 @@ def main(): cfg.load() variables = cfg.variables() - (category, variablelist) = variables['plc_dns'] - plc_dns = dict(zip(variablelist.keys(), - [variable['value'] for variable in variablelist.values()])) + (_, variablelist) = variables['plc_dns'] + plc_dns = dict(list(zip(list(variablelist.keys()), + [variable['value'] + for variable in list(variablelist.values())]))) if plc_dns['enabled'] != "true": return 0 @@ -55,7 +56,7 @@ def main(): nodes[node['node_id']] = node interface_ids = set() - for node in nodes.values(): + for node in list(nodes.values()): interface_ids.update(node['interface_ids']) for interface in GetInterfaces(list(interface_ids)): @@ -67,16 +68,16 @@ def main(): else: hostname = nodes[interface['node_id']]['hostname'] - if hosts.has_key(interface['ip']): + if interface['ip'] in hosts: if hostname not in hosts[interface['ip']]: hosts[interface['ip']].append(hostname) else: hosts[interface['ip']] = [hostname] - + # Write /etc/plc_hosts plc_hosts = open("/etc/plc_hosts", "w") - plc_hosts.write("# DO NOT EDIT; File is writen and removed by automatic scripts\n") - for ip, hostnames in hosts.iteritems(): + plc_hosts.write("# DO NOT EDIT; File is written and removed by automatic scripts\n") + for ip, hostnames in hosts.items(): plc_hosts.write(ip + "\t" + " ".join(hostnames) + "\n") plc_hosts.close() @@ -87,7 +88,8 @@ def main(): # the public DNS cannot answer, and which load the servers # (especially the root servers) uneccessarily. # - file("/etc/dnsmasq.conf", "w").write(""" + with open("/etc/dnsmasq.conf", "w") as writer: + writer.write(""" domain-needed bogus-priv addn-hosts=/etc/plc_hosts