From 116c617b862723347606d74f9961ba6dca034fe9 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Jan 29 2020 13:08:44 +0000 Subject: arch_utils: Fix ResourceWarnings 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ář --- diff --git a/pungi/arch_utils.py b/pungi/arch_utils.py index e3b8636..82180c3 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