mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 12:49:01 +02:00
Use try...finally or with to ensure files get closed
Best practices state that you should use a mechanism that ensures files get closed in case of any error, so let's do that. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
24739d9369
commit
9c65bf254e
|
@ -55,16 +55,20 @@ def generate_patches(tinfoil, fetchdir, changeset, outputdir):
|
|||
(tmptarfd, tmptarname) = tempfile.mkstemp('.tar.gz', 'bulkchange-', outputdir)
|
||||
tmptarfile = os.fdopen(tmptarfd, "wb")
|
||||
tar = tarfile.open(None, "w:gz", tmptarfile)
|
||||
try:
|
||||
for patch in patches:
|
||||
patchfn = os.path.join(tmpoutdir, patch)
|
||||
tar.add(patchfn, arcname=patch)
|
||||
finally:
|
||||
tar.close()
|
||||
ret = tmptarname
|
||||
elif len(patches) == 1:
|
||||
(tmppatchfd, tmppatchname) = tempfile.mkstemp('.patch', 'bulkchange-', outputdir)
|
||||
tmppatchfile = os.fdopen(tmppatchfd, "wb")
|
||||
try:
|
||||
with open(os.path.join(tmpoutdir, patches[0]), "rb") as patchfile:
|
||||
shutil.copyfileobj(patchfile, tmppatchfile)
|
||||
finally:
|
||||
tmppatchfile.close()
|
||||
ret = tmppatchname
|
||||
|
||||
|
|
|
@ -1457,6 +1457,7 @@ def task_log_view(request, task_id):
|
|||
f = open(os.path.join(settings.TASK_LOG_DIR, 'task_%s.log' % task_id), 'rb')
|
||||
except FileNotFoundError:
|
||||
raise Http404
|
||||
try:
|
||||
f.seek(int(start))
|
||||
# We need to escape this or else things that look like tags in the output
|
||||
# will be interpreted as such by the browser
|
||||
|
@ -1476,6 +1477,8 @@ def task_log_view(request, task_id):
|
|||
response['Task-Done'] = '0'
|
||||
preader = utils.ProgressReader(settings.TASK_LOG_DIR, task_id)
|
||||
response['Task-Progress'] = preader.read()
|
||||
finally:
|
||||
f.close()
|
||||
return response
|
||||
|
||||
def task_stop_view(request, task_id):
|
||||
|
|
|
@ -69,15 +69,13 @@ def search_package_in_distros(pkglst_dir, recipe, data):
|
|||
else:
|
||||
pn = recipe_name
|
||||
|
||||
f = open(os.path.join(pkglst_dir, distro_file), "r")
|
||||
with open(os.path.join(pkglst_dir, distro_file), "r") as f:
|
||||
for line in f:
|
||||
(pkg, section) = line.split(":")
|
||||
if pn == pkg:
|
||||
distro_complete = distro + "-" + section[:-1]
|
||||
distros[distro_complete] = pn
|
||||
f.close()
|
||||
break
|
||||
f.close()
|
||||
|
||||
return distros
|
||||
|
||||
|
|
|
@ -102,8 +102,9 @@ def maintainers_inc_history(options, logger, maintplan, layerbranch, repodir, la
|
|||
utils.runcmd("git checkout %s -f" % commit,
|
||||
repodir, logger=logger)
|
||||
|
||||
lines = [line.strip() for line in open(maintainers_full_path)]
|
||||
for line in lines:
|
||||
with open(maintainers_full_path, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
res = get_recipe_maintainer(line, logger)
|
||||
if res:
|
||||
(pn, name, email) = res
|
||||
|
|
Loading…
Reference in New Issue
Block a user