From 9f3408fec06df408d07549b9302a1e12e789dba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 26 Apr 2016 14:58:18 +0200 Subject: [PATCH] [pkgset] Use context manager for opening file list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lubomír Sedlář --- pungi/phases/pkgset/pkgsets.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pungi/phases/pkgset/pkgsets.py b/pungi/phases/pkgset/pkgsets.py index 83917736..5ebcd90a 100644 --- a/pungi/phases/pkgset/pkgsets.py +++ b/pungi/phases/pkgset/pkgsets.py @@ -171,14 +171,13 @@ class PackageSetBase(kobo.log.LoggingBase): self.log_debug("[DONE ] %s" % msg) def save_file_list(self, file_path, remove_path_prefix=None): - f = open(file_path, "w") - for arch in sorted(self.rpms_by_arch): - for i in self.rpms_by_arch[arch]: - rpm_path = i.file_path - if remove_path_prefix and rpm_path.startswith(remove_path_prefix): - rpm_path = rpm_path[len(remove_path_prefix):] - f.write("%s\n" % rpm_path) - f.close() + with open(file_path, "w") as f: + for arch in sorted(self.rpms_by_arch): + for i in self.rpms_by_arch[arch]: + rpm_path = i.file_path + if remove_path_prefix and rpm_path.startswith(remove_path_prefix): + rpm_path = rpm_path[len(remove_path_prefix):] + f.write("%s\n" % rpm_path) class FilelistPackageSet(PackageSetBase):