aboutsummaryrefslogtreecommitdiffstats
path: root/lib/toaster
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2023-12-05 16:03:25 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-12-06 22:27:21 +0000
commite8574ee78eea23cc35900610bb15e47e40ef5ee1 (patch)
tree1b4ad3c591960999f88ce8086e7caaf5d9d5bc6d /lib/toaster
parent81ee203fd55d45b199d7c3af681855d254e0d876 (diff)
downloadbitbake-e8574ee78eea23cc35900610bb15e47e40ef5ee1.tar.gz
toastermain/settings: Avoid python filehandle closure warnings
Switch to using with blocks when accessing files to ensure file descriptors are closed and avoid python warnings. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/toaster')
-rw-r--r--lib/toaster/toastermain/settings.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/toaster/toastermain/settings.py b/lib/toaster/toastermain/settings.py
index 3c1235936..e06adc5a9 100644
--- a/lib/toaster/toastermain/settings.py
+++ b/lib/toaster/toastermain/settings.py
@@ -89,14 +89,17 @@ else:
from pytz.exceptions import UnknownTimeZoneError
try:
if pytz.timezone(zonename) is not None:
- zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename
+ with open(filepath, 'rb') as f:
+ zonefilelist[hashlib.md5(f.read()).hexdigest()] = zonename
except UnknownTimeZoneError as ValueError:
# we expect timezone failures here, just move over
pass
except ImportError:
- zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename
+ with open(filepath, 'rb') as f:
+ zonefilelist[hashlib.md5(f.read()).hexdigest()] = zonename
- TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime', 'rb').read()).hexdigest()]
+ with open('/etc/localtime', 'rb') as f:
+ TIME_ZONE = zonefilelist[hashlib.md5(f.read()).hexdigest()]
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html