Open and close file descriptors.

We noticed this when working on the Bodhi integration.

Signed-off-by: Ralph Bean <rbean@redhat.com>
This commit is contained in:
Ralph Bean 2017-10-10 12:47:21 -04:00
parent c89f033457
commit 97d52d03c8
4 changed files with 11 additions and 5 deletions

View File

@ -268,7 +268,9 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
for config_file in compose.conf.opened_files:
config_dump = compose.paths.log.log_file("global", "config-copy_%s_%s"
% (os.path.basename(config_file), date_str))
open(config_dump, "w").write(open(config_file, 'r').read())
with open(config_dump, "w") as dest:
with open(config_file, 'r').read() as src:
dest.write(src.read())
config_dump_full = compose.paths.log.log_file("global", "config-dump_%s" % date_str)
with open(config_dump_full, "w") as f:
json.dump(compose.conf, f, sort_keys=True, indent=4)
@ -463,7 +465,8 @@ if __name__ == "__main__":
COMPOSE.log_critical("Compose failed: %s" % COMPOSE.topdir)
COMPOSE.write_status("DOOMED")
import kobo.tback
open(tb_path, "w").write(kobo.tback.Traceback().get_traceback())
with open(tb_path, "w") as f:
f.write(kobo.tback.Traceback().get_traceback())
else:
print("Exception: %s" % ex)
raise

View File

@ -85,7 +85,8 @@ def get_compose_dir(topdir, conf, compose_type="production", compose_date=None,
continue
break
open(os.path.join(compose_dir, "COMPOSE_ID"), "w").write(ci.compose.id)
with open(os.path.join(compose_dir, "COMPOSE_ID"), "w") as f:
f.write(ci.compose.id)
work_dir = os.path.join(compose_dir, "work", "global")
makedirs(work_dir)
ci.dump(os.path.join(work_dir, "composeinfo-base.json"))

View File

@ -423,7 +423,8 @@ class BuildinstallThread(WorkerThread):
log_file = compose.paths.log.log_file(arch, log_filename + '-RPMs')
rpms = get_buildroot_rpms(compose, task_id)
open(log_file, "w").write("\n".join(rpms))
with open(log_file, "w") as f:
f.write("\n".join(rpms))
self.pool.finished_tasks.add((variant.uid if variant else None, arch))
self.pool.log_info("[DONE ] %s" % msg)

View File

@ -414,7 +414,8 @@ def prepare_iso(compose, arch, variant, disc_num=1, disc_count=None, split_iso_d
if file_list_content:
# write modified repodata only if there are packages available
run("cp -a %s/repodata %s/" % (pipes.quote(tree_dir), pipes.quote(iso_dir)))
open(file_list, "w").write("\n".join(file_list_content))
with open(file_list, "w") as f:
f.write("\n".join(file_list_content))
cmd = repo.get_createrepo_cmd(tree_dir, update=True, database=True, skip_stat=True, pkglist=file_list, outputdir=iso_dir, workers=3, checksum=createrepo_checksum)
run(cmd)
# add repodata/repomd.xml back to checksums