diff --git a/bin/pungi-koji b/bin/pungi-koji index e08d8dc1..613e94ed 100755 --- a/bin/pungi-koji +++ b/bin/pungi-koji @@ -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 diff --git a/pungi/compose.py b/pungi/compose.py index d49b0f3e..90ac2011 100644 --- a/pungi/compose.py +++ b/pungi/compose.py @@ -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")) diff --git a/pungi/phases/buildinstall.py b/pungi/phases/buildinstall.py index c02b6bc3..9d805bcd 100644 --- a/pungi/phases/buildinstall.py +++ b/pungi/phases/buildinstall.py @@ -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) diff --git a/pungi/phases/createiso.py b/pungi/phases/createiso.py index a0d7f425..b2a0b95a 100644 --- a/pungi/phases/createiso.py +++ b/pungi/phases/createiso.py @@ -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