Close files after use

Replace the pattern:

  func(open(...))

by the pattern:

  with open(...) as f:
    func(f)

It ensures files are closed after use.

Change-Id: I7cdd08993ae4a094d101a1bf68ce700817e7fb92
This commit is contained in:
Cedric Brandily 2014-09-25 14:36:39 +02:00
parent 022610fe86
commit 20e9713de0
3 changed files with 6 additions and 3 deletions

View File

@ -37,7 +37,8 @@ class DoxYaml(object):
def _open_dox_yaml(self):
if self._yaml is None:
self._yaml = yaml.load(open('dox.yml', 'r'))
with open('dox.yml', 'r') as f:
self._yaml = yaml.load(f)
return self._yaml
def exists(self):

View File

@ -37,7 +37,8 @@ class TravisYaml(object):
def _open_travis_yaml(self):
if self._yaml is None:
self._yaml = yaml.load(open('travis.yml', 'r'))
with open('travis.yml', 'r') as f:
self._yaml = yaml.load(f)
return self._yaml
def exists(self):

View File

@ -138,7 +138,8 @@ class Runner(object):
for command in commands.prep_commands():
dockerfile.append("RUN %s\n" % command)
dockerfile = '\n'.join(dockerfile)
open(os.path.join(tempd, 'Dockerfile'), 'w').write(dockerfile)
with open(os.path.join(tempd, 'Dockerfile'), 'w') as f:
f.write(dockerfile)
logger.debug("Dockerfile:\n" + self._indent(dockerfile))
self._docker_build(self.test_image_name, tempd)
finally: