From 116c617b862723347606d74f9961ba6dca034fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 29 Jan 2020 13:02:29 +0100 Subject: [PATCH] arch_utils: Fix ResourceWarnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Newer versions of Python report an error when a file is not closed. Let's avoid it by using with statement. Signed-off-by: Lubomír Sedlář --- pungi/arch_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pungi/arch_utils.py b/pungi/arch_utils.py index e3b86362..82180c3d 100644 --- a/pungi/arch_utils.py +++ b/pungi/arch_utils.py @@ -145,7 +145,8 @@ def _try_read_cpuinfo(): # pragma: no cover """ Try to read /proc/cpuinfo ... if we can't ignore errors (ie. proc not mounted). """ try: - return open("/proc/cpuinfo", "r") + with open("/proc/cpuinfo", "r") as f: + return f.readlines() except: return [] @@ -155,7 +156,8 @@ def _parse_auxv(): # pragma: no cover later on, very similar to what rpm does. """ # In case we can't open and read /proc/self/auxv, just return try: - data = open("/proc/self/auxv", "rb").read() + with open("/proc/self/auxv", "rb") as f: + data = f.read() except: return