From e45ff0a6db152273a3ce7159cc770bf58fdb5156 Mon Sep 17 00:00:00 2001 From: parmentelat Date: Tue, 18 Dec 2018 15:34:30 +0100 Subject: [PATCH] dns-config still had occurrences of file() --- bin/dns-config | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bin/dns-config b/bin/dns-config index 11a5318..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)) 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'] + (_, variablelist) = variables['plc_dns'] plc_dns = dict(list(zip(list(variablelist.keys()), - [variable['value'] for variable in list(variablelist.values())]))) + [variable['value'] + for variable in list(variablelist.values())]))) if plc_dns['enabled'] != "true": return 0 @@ -72,10 +73,10 @@ def main(): 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") + 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 -- 2.43.0