Merge lp:~oem-qa/checkbox/patch_exit_on_whitelist_file_not_found into lp:checkbox

Proposed by Javier Collado
Status: Merged
Merged at revision: 951
Proposed branch: lp:~oem-qa/checkbox/patch_exit_on_whitelist_file_not_found
Merge into: lp:checkbox
Diff against target: 25 lines (+6/-3)
1 file modified
plugins/jobs_info.py (+6/-3)
To merge this branch: bzr merge lp:~oem-qa/checkbox/patch_exit_on_whitelist_file_not_found
Reviewer Review Type Date Requested Status
Daniel Manrique (community) Approve
Review via email: mp+67810@code.launchpad.net

Commit message

Print error message and exit on whitelist/blacklist file not found

Description of the change

When a user mistypes the name of the whitelist/blacklist file in the command line:
- checkbox execution isn't stopped even if the file doesn't exist
- just an info line is displayed in logs: "Failed to open file '%s': %s"
- whitelist/blacklist patterns aren't applied (without providing any feedback regarding the reason to the user)

With this change:
- filenames passed through the command line are checked
- if a file doesn't exist an error message is printed to stderr and the application exits

Low level details:
- Logging level for the error messsage set to critical since this problem now causes the whole application to exit abruptly.
- Exit code is set to EX_NOINPUT which is the recommended one for files not found or not readable.

To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

Thanks Javier, this works fine with both the shorthand and extended whitelist/blacklist syntax, I just added a gettext.gettext call to the error string.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/jobs_info.py'
2--- plugins/jobs_info.py 2011-01-12 21:08:53 +0000
3+++ plugins/jobs_info.py 2011-07-13 14:22:30 +0000
4@@ -16,7 +16,7 @@
5 # You should have received a copy of the GNU General Public License
6 # along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
7 #
8-import re
9+import os, sys, re
10 import gettext
11 import logging
12
13@@ -78,8 +78,11 @@
14 try:
15 file = open(filename)
16 except IOError, e:
17- logging.info("Failed to open file '%s': %s",
18- filename, e.strerror)
19+ error_message=("Failed to open file '%s': %s"
20+ % (filename, e.strerror))
21+ logging.critical(error_message)
22+ sys.stderr.write("%s\n" % error_message)
23+ sys.exit(os.EX_NOINPUT)
24 else:
25 strings.extend([l.strip() for l in file.readlines()])
26

Subscribers

People subscribed via source and target branches