close more filehandles with context managers

This commit is contained in:
Brian Warner 2016-09-13 22:17:22 -07:00
parent 3282f2aa8a
commit aa162f5a90
3 changed files with 9 additions and 9 deletions

View File

@ -127,7 +127,8 @@ class Node(service.MultiService):
self.config_fname = os.path.join(self.basedir, "tahoe.cfg") self.config_fname = os.path.join(self.basedir, "tahoe.cfg")
self._portnumfile = os.path.join(self.basedir, self.PORTNUMFILE) self._portnumfile = os.path.join(self.basedir, self.PORTNUMFILE)
fileutil.make_dirs(os.path.join(self.basedir, "private"), 0700) fileutil.make_dirs(os.path.join(self.basedir, "private"), 0700)
open(os.path.join(self.basedir, "private", "README"), "w").write(PRIV_README) with open(os.path.join(self.basedir, "private", "README"), "w") as f:
f.write(PRIV_README)
# creates self.config # creates self.config
self.read_config() self.read_config()
@ -497,7 +498,8 @@ class Node(service.MultiService):
return it. return it.
""" """
privname = os.path.join(self.basedir, "private", name) privname = os.path.join(self.basedir, "private", name)
open(privname, "w").write(value) with open(privname, "w") as f:
f.write(value)
def get_private_config(self, name, default=_None): def get_private_config(self, name, default=_None):
"""Read the (string) contents of a private config file (which is a """Read the (string) contents of a private config file (which is a

View File

@ -218,12 +218,9 @@ def create_node(config):
os.mkdir(basedir) os.mkdir(basedir)
write_tac(basedir, "client") write_tac(basedir, "client")
c = open(os.path.join(basedir, "tahoe.cfg"), "w") with open(os.path.join(basedir, "tahoe.cfg"), "w") as c:
write_node_config(c, config)
write_node_config(c, config) write_client_config(c, config)
write_client_config(c, config)
c.close()
from allmydata.util import fileutil from allmydata.util import fileutil
fileutil.make_dirs(os.path.join(basedir, "private"), 0700) fileutil.make_dirs(os.path.join(basedir, "private"), 0700)

View File

@ -183,7 +183,8 @@ def stop(config):
# we define rc=2 to mean "nothing is running, but it wasn't me who # we define rc=2 to mean "nothing is running, but it wasn't me who
# stopped it" # stopped it"
return 2 return 2
pid = open(pidfile, "r").read() with open(pidfile, "r") as f:
pid = f.read()
pid = int(pid) pid = int(pid)
# kill it hard (SIGKILL), delete the twistd.pid file, then wait for the # kill it hard (SIGKILL), delete the twistd.pid file, then wait for the