Merge ~bladernr/plainbox-provider-checkbox:1896119-boot_mode_test-hang into plainbox-provider-checkbox:master

Proposed by Jeff Lane 
Status: Merged
Approved by: Jeff Lane 
Approved revision: c5cc8a39aedd9be41e063d7b9290ffcd7a16b015
Merged at revision: 6fdde642454ca3c330342423c6c1692d54e79df9
Proposed branch: ~bladernr/plainbox-provider-checkbox:1896119-boot_mode_test-hang
Merge into: plainbox-provider-checkbox:master
Diff against target: 24 lines (+4/-2)
1 file modified
bin/boot_mode_test.py (+4/-2)
Reviewer Review Type Date Requested Status
Jonathan Cave (community) Approve
Review via email: mp+395963@code.launchpad.net

Description of the change

Modify the file opens so that filehandles close properly and aren't just left hanging for python garbage collection to clean them up.

To post a comment you must log in.
Revision history for this message
Jonathan Cave (jocave) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/boot_mode_test.py b/bin/boot_mode_test.py
2index e51a099..7d7299a 100755
3--- a/bin/boot_mode_test.py
4+++ b/bin/boot_mode_test.py
5@@ -68,7 +68,8 @@ def reboot_to_firmware_check():
6 "OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c"
7 if os.path.isdir(osis_dir):
8 if os.path.isfile(osis_var):
9- fw_info = open(osis_var).read()
10+ with open(osis_var) as fh:
11+ fw_info = fh.read()
12 if ord(fw_info[4]) & 1:
13 logging.info("PASS: Reboot-to-firmware feature is present.")
14 return 0
15@@ -95,7 +96,8 @@ def secure_boot_check():
16 sb_var = sb_dir + "SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c"
17 if os.path.isdir(sb_dir):
18 if os.path.isfile(sb_var):
19- sb_info = open(sb_var).read()
20+ with open(sb_var) as fh:
21+ sb_info = fh.read()
22 if ord(sb_info[4]) == 1:
23 logging.info("PASS: System booted with Secure Boot active.")
24 return 0

Subscribers

People subscribed via source and target branches