git://git.onelab.eu
/
myplc.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4ec8564
)
dns-config still had occurrences of file()
author
parmentelat
<thierry.parmentelat@inria.fr>
Tue, 18 Dec 2018 14:34:30 +0000
(15:34 +0100)
committer
parmentelat
<thierry.parmentelat@inria.fr>
Tue, 18 Dec 2018 14:34:30 +0000
(15:34 +0100)
bin/dns-config
patch
|
blob
|
history
diff --git
a/bin/dns-config
b/bin/dns-config
index
11a5318
..
5e62668
100755
(executable)
--- a/
bin/dns-config
+++ b/
bin/dns-config
@@
-7,9
+7,11
@@
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
+# pylint: disable=c0111
+import sys
+import os
from plc_config import PLCConfiguration
from plc_config import PLCConfiguration
-import os, sys
def writepid(prog):
"""
def writepid(prog):
"""
@@
-17,18
+19,16
@@
def writepid(prog):
"""
try:
"""
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
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)
def removepid(prog):
os.unlink("/var/run/%s.pid" % prog)
@@
-40,9
+40,10
@@
def main():
cfg.load()
variables = cfg.variables()
cfg.load()
variables = cfg.variables()
- (
category
, variablelist) = variables['plc_dns']
+ (
_
, variablelist) = variables['plc_dns']
plc_dns = dict(list(zip(list(variablelist.keys()),
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
if plc_dns['enabled'] != "true":
return 0
@@
-72,10
+73,10
@@
def main():
hosts[interface['ip']].append(hostname)
else:
hosts[interface['ip']] = [hostname]
hosts[interface['ip']].append(hostname)
else:
hosts[interface['ip']] = [hostname]
-
+
# Write /etc/plc_hosts
plc_hosts = open("/etc/plc_hosts", "w")
# 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 writ
t
en and removed by automatic scripts\n")
for ip, hostnames in hosts.items():
plc_hosts.write(ip + "\t" + " ".join(hostnames) + "\n")
plc_hosts.close()
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.
#
# 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
domain-needed
bogus-priv
addn-hosts=/etc/plc_hosts