diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-12-05 16:03:25 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-12-06 22:28:03 +0000 |
commit | 786ba56074ca9374ae5b4f7b06e1d554f8169d23 (patch) | |
tree | fe76be200cd34e4918d1d19e6b3cb8b2cca49bfd | |
parent | c2484f3dec966b8698d921221185f35771ab58ef (diff) | |
download | poky-786ba56074ca9374ae5b4f7b06e1d554f8169d23.tar.gz |
bitbake: 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.
(Bitbake rev: e8574ee78eea23cc35900610bb15e47e40ef5ee1)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/toaster/toastermain/settings.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/bitbake/lib/toaster/toastermain/settings.py b/bitbake/lib/toaster/toastermain/settings.py index 3c12359366..e06adc5a93 100644 --- a/bitbake/lib/toaster/toastermain/settings.py +++ b/bitbake/lib/toaster/toastermain/settings.py | |||
@@ -89,14 +89,17 @@ else: | |||
89 | from pytz.exceptions import UnknownTimeZoneError | 89 | from pytz.exceptions import UnknownTimeZoneError |
90 | try: | 90 | try: |
91 | if pytz.timezone(zonename) is not None: | 91 | if pytz.timezone(zonename) is not None: |
92 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename | 92 | with open(filepath, 'rb') as f: |
93 | zonefilelist[hashlib.md5(f.read()).hexdigest()] = zonename | ||
93 | except UnknownTimeZoneError as ValueError: | 94 | except UnknownTimeZoneError as ValueError: |
94 | # we expect timezone failures here, just move over | 95 | # we expect timezone failures here, just move over |
95 | pass | 96 | pass |
96 | except ImportError: | 97 | except ImportError: |
97 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename | 98 | with open(filepath, 'rb') as f: |
99 | zonefilelist[hashlib.md5(f.read()).hexdigest()] = zonename | ||
98 | 100 | ||
99 | TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime', 'rb').read()).hexdigest()] | 101 | with open('/etc/localtime', 'rb') as f: |
102 | TIME_ZONE = zonefilelist[hashlib.md5(f.read()).hexdigest()] | ||
100 | 103 | ||
101 | # Language code for this installation. All choices can be found here: | 104 | # Language code for this installation. All choices can be found here: |
102 | # http://www.i18nguy.com/unicode/language-identifiers.html | 105 | # http://www.i18nguy.com/unicode/language-identifiers.html |