Merge lp:~kissiel/checkbox/verbosity-settings-in-cbt into lp:checkbox

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Zygmunt Krynicki
Approved revision: 3872
Merged at revision: 3876
Proposed branch: lp:~kissiel/checkbox/verbosity-settings-in-cbt
Merge into: lp:checkbox
Diff against target: 129 lines (+47/-15)
2 files modified
checkbox-touch/checkbox-touch.qml (+38/-13)
checkbox-touch/py/checkbox_touch.py (+9/-2)
To merge this branch: bzr merge lp:~kissiel/checkbox/verbosity-settings-in-cbt
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+263649@code.launchpad.net

Description of the change

This MR fixes a few design problems that were required to bring --quiet mode in. See log for details. After those fixes are applied it introduces the quiet mode and makes autopilot use it.

0e0ddb1 checkbox-touch: move initialization of pyotherside to init()
5f044fb checkbox-touch: add 'initiated' signal to Python{} object
9244cc7 checkbox-touch: make components using Py to wait for py.onInitiated
f1bb1c7 checkbox-touch: move py.init() to mainView.onCompleted
33e25cb checkbox-touch: make loading of settings.json append, not overwrite
712ba49 checkbox-touch: initiating logger now requires default logging level
3351f21 checkbox-touch: add --quiet option to the app
9679197 checkbox-touch: imply quiet mode when running autopilot
99b4924 checkbox-touch: add semicolons in the JS bits

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

13:02 < zyga> kissiel: http://bazaar.launchpad.net/~kissiel/checkbox/verbosity-settings-in-cbt/revision/3870 this is a bit iffy
13:02 < zyga> kissiel: but everything else in that branch is great
13:02 < zyga> kissiel: I don't know how to improve it, it just ... meh, javascript is so crap, we'd have to roll or own logging library
13:03 < zyga> kissiel: or import something external

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox-touch/checkbox-touch.qml'
2--- checkbox-touch/checkbox-touch.qml 2015-06-25 15:42:19 +0000
3+++ checkbox-touch/checkbox-touch.qml 2015-07-02 12:54:55 +0000
4@@ -69,13 +69,19 @@
5 help: i18n.tr("Run Checkbox-Touch in autopilot-testing mode")
6 required: false
7 }
8+ Argument {
9+ name: "quiet"
10+ help: i18n.tr("Write only warnings and errors to standard error")
11+ required: false
12+ }
13 }
14
15 Component.onCompleted: {
16 if (args.values["autopilot"]) {
17 // autopilot-testing mode
18- appSettings["testplan"] = "2015.com.canonical.certification::checkbox-touch-autopilot"
19- appSettings["providersDir"] = "tests/autopilot/autopilot-provider"
20+ appSettings["testplan"] = "2015.com.canonical.certification::checkbox-touch-autopilot";
21+ appSettings["providersDir"] = "tests/autopilot/autopilot-provider";
22+ appSettings["log-level"] = "warning";
23 } else {
24 // normal execution - load settings.json file
25 var xhr = new XMLHttpRequest;
26@@ -83,37 +89,48 @@
27 xhr.onreadystatechange = function() {
28 if (xhr.readyState == XMLHttpRequest.DONE) {
29 try {
30- appSettings = JSON.parse(xhr.responseText);
31+ var newAppSettings = JSON.parse(xhr.responseText);
32 } catch (x) {
33 // if we cannot parse settings.json, we should leave
34 // deafult values of appSettings
35- console.log("Could not parse settings.json. Using default values")
36+ console.error("Could not parse settings.json. Using default values");
37+ }
38+ // overwrite/add appSettings' attributes that got loaded
39+ for (var attr in newAppSettings) {
40+ appSettings[attr] = newAppSettings[attr];
41 }
42 }
43 }
44 xhr.send();
45 }
46+ if (args.values["quiet"]) {
47+ // monkey-patch console.log and console.info to do nothing
48+ console.log = function() {};
49+ console.info = function() {};
50+ appSettings["log-level"] = "warning";
51+ }
52+ py.init()
53 }
54
55
56 // Pyotherside python object that we use to talk to all of plainbox
57 Python {
58 id: py
59- Component.onCompleted: {
60+
61+ function init() {
62 console.log("Pyotherside version " + pluginVersion());
63 console.log("Python version " + pythonVersion());
64 // A bit hacky but that's where the python code is
65 addImportPath(Qt.resolvedUrl('py/'));
66 // Import path for plainbox and potentially other python libraries
67 addImportPath(Qt.resolvedUrl('lib/py'))
68- // Import the checkbox_touch module on startup then call the
69- // create_app_object() function and assign the resulting handle
70- // back to the application component.
71- py.importModule("checkbox_touch", function() {
72- app.construct("checkbox_touch.create_app_object", [])
73- });
74 setHandler('command_output', commandOutputPage.addText);
75+ initiated();
76 }
77+
78+ // gets triggered when python object is ready to be used
79+ signal initiated
80+
81 onError: {
82 console.error("python error: " + traceback);
83 ErrorLogic.showError(mainView, "python error: " + traceback, Qt.quit);
84@@ -137,15 +154,23 @@
85 onSessionReady: {
86 welcomePage.enableButton()
87 }
88+ Component.onCompleted: {
89+ // register to py.initiated signal
90+ py.onInitiated.connect(function() {
91+ construct("checkbox_touch.create_app_object", []);
92+ });
93+ }
94 }
95
96 PythonLogger {
97 id: logger
98 py: py
99 Component.onCompleted: {
100- py.Component.onCompleted.connect(function() {
101+ // register to py.initiated signal
102+ py.onInitiated.connect(function() {
103 py.importModule("checkbox_touch", function() {
104- construct("checkbox_touch.get_qml_logger", []);
105+ construct("checkbox_touch.get_qml_logger",
106+ [appSettings["log-level"] || "info"]);
107 });
108 });
109 }
110
111=== modified file 'checkbox-touch/py/checkbox_touch.py'
112--- checkbox-touch/py/checkbox_touch.py 2015-06-25 15:42:19 +0000
113+++ checkbox-touch/py/checkbox_touch.py 2015-07-02 12:54:55 +0000
114@@ -657,8 +657,15 @@
115 self._password = password
116
117
118-def get_qml_logger():
119- logging.basicConfig(level=logging.INFO, stream=sys.stderr)
120+def get_qml_logger(default_level):
121+ logging_level = collections.defaultdict(lambda:logging.INFO, {
122+ "debug": logging.DEBUG,
123+ "warning": logging.WARNING,
124+ "warn": logging.WARN,
125+ "error": logging.ERROR,
126+ "critical": logging.CRITICAL,
127+ "fatal": logging.FATAL})[default_level.lower()]
128+ logging.basicConfig(level=logging_level, stream=sys.stderr)
129 return logging.getLogger('checkbox.touch.qml')
130
131

Subscribers

People subscribed via source and target branches