2
* This file is part of Checkbox
4
* Copyright 2014-2015 Canonical Ltd.
7
* - Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
8
* - Maciej Kisielewski <maciej.kisielewski@canonical.com>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; version 3.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
import Ubuntu.Components 1.1
25
import "ErrorLogic.js" as ErrorLogic
30
// Version of the application
31
property string applicationVersion
32
// Version of the plainbox library
33
property string plainboxVersion
34
// path to session storage directory
35
property string sessionDir
37
// Signal sent when the application becomes ready
40
// Signal sent when a session becomes ready
43
// Create a new session
45
// Starts session in plainbox and runs all necessary setup actions.
46
// Calling this function will signal sessionReady() once it's finished
48
function startSession() {
49
request("start_session", [], function(result) {
50
sessionDir = result['session_dir'];
53
console.error("Unable to start session: " + error);
54
ErrorLogic.showError(mainView,
55
i18n.tr("Could not start a session. Reason:\n" + error),
60
function resumeSession(rerunLastTest, continuation) {
61
request("resume_session", [rerunLastTest], function(result) {
62
if (!result["session_id"]) {
64
ErrorLogic.showError(mainView,
65
i18n.tr("Could not resume session"),
70
i18n.tr("Start new session"));
72
sessionDir = result['session_dir'];
78
console.error("Unable to resume session: " + error);
81
function clearSession(continuation) {
82
request("clear_session", [], continuation, function(error) {
83
console.error("Unable to clear session: " + error);
87
function isSessionResumable(continuation) {
88
request("is_session_resumable", [], continuation, function(error) {
89
console.error("Unable to check session resumability");
93
function getTestplans(continuation) {
94
request("get_testplans", [], continuation, function(error) {
95
console.error("Unable to get testplans");
98
function rememberTestplan(testplan, continuation) {
99
var handleResult = function(result) {
100
sessionDir = result['session_dir'];
103
request("remember_testplan", [testplan], handleResult, function(error) {
104
console.error("Unable to save testplan selection");
108
function getCategories(continuation) {
109
request("get_categories", [], continuation, function(error) {
110
console.error("Unable to get categories");
114
function rememberCategorySelection(categories, continuation) {
115
request("remember_categories", [categories], continuation, function(error) {
116
console.error("Unable to save category selection");
120
function getTests(continuation) {
121
request("get_available_tests", [], continuation, function(error) {
122
console.error("Unable to get tests");
126
function rememberTestSelection(tests, continuation) {
127
request("remember_tests", [tests], continuation, function(error) {
128
console.error("Unable to save test selection");
132
function getNextTest(continuation) {
133
request("get_next_test", [], continuation, function(error) {
134
console.error("Unable to get next test");
138
function registerTestResult(test, continuation) {
139
request("register_test_result", [test], continuation, function(error) {
140
console.error("Unable to save test result");
144
function runTestActivity(test, continuation) {
145
request("run_test_activity", [test], continuation, function(error) {
146
console.error("Unable to run test activity");
150
function getRerunCandidates(continuation) {
151
request("get_rerun_candidates", [], continuation, function(error) {
152
console.error("Unable to get rerun candidates");
156
function getResults(continuation) {
157
request("get_results", [], continuation, function(error) {
158
console.error("Unable to get test results");
162
function exportResults(output_format, option_list, continuation) {
163
request("export_results", [output_format, option_list], continuation, function(error) {
164
console.error("Unable to export test results");
167
function submitResults(config, continuation, continuation_error) {
168
// Use low-level call as the config may contain sensitive information.
169
var callable = py.getattr(object, "submit_results");
171
console.error("Unable to invoke submit_results!");
172
throw "trying to invoke not existing method";
174
py.call(callable, [config], function(response) {
175
if (response.code == 200) {
176
continuation(response.result);
178
continuation_error(response.error)
182
function dropPermissions(appId, services, continuation, continuation_error) {
183
request("drop_permissions", [appId, services], continuation, function(error) {
184
console.error("Unable to remove permissions");
185
if (continuation_error) continuation_error(error);
188
function getIncompleteSessions(continuation) {
189
request("get_incomplete_sessions", [], continuation, function(error) {
190
console.error("Unable to get incomplete sessions")
193
function deleteOldSessions(sessionIds, continuation) {
194
request("delete_old_sessions", [sessionIds], continuation, function(error) {
195
console.error("Unable to remove old sessions")
199
function rememberPassword(password, continuation) {
200
// using low-level py.call() to 'silently' pass password string through pyotherside
201
var callable = py.getattr(object, "remember_password");
203
console.error("Unable to invoke remember_password!");
204
throw "trying to invoke not existing method";
206
py.call(callable, [password], function(response) {
207
continuation(response);
211
// A wrapper around invoke() that works with the @view decorator. The fn_ok
212
// and fn_err are called on a normal reply and on error, respectively.
213
function request(name, args, fn_ok, fn_err) {
214
invoke(name, args, function(response) {
215
if (response.code == 200) {
216
fn_ok(response.result);
218
fn_err(response.error);
223
// Internal handler that triggers a call to python to query for runtime and
224
// application versions.
226
request("load_providers", [appSettings["providersDir"]], function(result) {
227
request("get_version_pair", [], function(result) {
228
app.applicationVersion = result.application_version;
229
app.plainboxVersion = result.plainbox_version;
232
console.error("Unable to query for version: " + error);
236
console.error("Unable to load providers: " + error);
237
ErrorLogic.showError(mainView, i18n.tr("No providers available!"), Qt.quit);