Commit 65b6ce07 authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Fix minor bugs and omissions

In protocol.py, correct the WebSocketProtocol docstring.
In gui/protocol.js create a simple method for debug logs.
In gui/menu.html use the aforementioned method.
In protocol.js make sure the connection is closed at shutdown.
In gui.py, remove the GUI session file even when quitting abnormally
Ignore "exclude" setting for now
parent 76054d6d
......@@ -27,7 +27,7 @@ HANDLER = logging.FileHandler(LOGFILE)
FORMATTER = logging.Formatter("%(levelname)s:%(asctime)s:%(message)s")
HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(HANDLER)
LOGGER.setLevel(logging.DEBUG)
LOGGER.setLevel(logging.INFO)
# run cli
from agkyra.cli import AgkyraCLI
......
......@@ -60,12 +60,23 @@ class GUI(WebSocketBaseClient):
os.write(f, json.dumps(session))
os.close(f)
def clean_exit(self):
"""Clean up tracks of GUI"""
try:
os.remove(self.session_file)
LOG.debug('Removed GUI session file')
except Exception as e:
LOG.warning('While cleaning GUI: %s' % e)
self.close()
def handshake_ok(self):
"""If handshake OK is, SessionHelper UP goes, so GUI launched can be"""
LOG.debug('Protocol server is UP, running GUI')
subprocess.call([self.nw, self.gui_code, self.session_file])
try:
subprocess.call([self.nw, self.gui_code, self.session_file])
finally:
self.clean_exit()
LOG.debug('GUI finished, close GUI wrapper connection')
self.close()
def run():
......@@ -81,7 +92,7 @@ def run():
gui.start()
except KeyboardInterrupt:
LOG.info('Shutdown GUI')
gui.close()
gui.clean_exit()
LOG.info('Shutdown SessionHelper server')
helper.shutdown()
......
......@@ -23,8 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<script src="static/js/jquery.js"></script>
<script type="text/javascript">
var DEBUG = true;
// Setup GUI
var windows = {
"settings": null,
......@@ -76,7 +74,7 @@ var local_folder_menu = new gui.MenuItem({
enabled: false,
click: function () {
var dir = globals['settings']['directory'];
if (DEBUG) console.log('Open ' + dir);
log_debug('Open ' + dir);
gui.Shell.showItemInFolder(dir);
}
})
......@@ -87,7 +85,7 @@ var pithos_page_menu = new gui.MenuItem({
icon: 'static/images/pithos.png',
enabled: false,
click: function () {
if (DEBUG) console.log('Visit ' + get_pithos_ui());
log_debug('Visit ' + get_pithos_ui());
gui.Shell.openExternal(get_pithos_ui());
}
});
......@@ -109,11 +107,11 @@ var settings_menu = new gui.MenuItem({
width: 860, height: 620
});
windows['settings'].on('closed', function() {
if (DEBUG) console.log('Settings windows is closed');
log_debug('Settings windows is closed');
var new_settings = import_settings();
$.each(new_settings, function(key, setting) {
if (old_settings[key] !== setting) {
if (DEBUG) console.log('Settings have been modified - updating...');
log_debug('Settings have been modified - updating...');
put_settings(socket, new_settings);
get_status(socket);
get_settings(socket);
......
......@@ -14,5 +14,6 @@
}],
"licences": [{"type": "GPLv3"}],
"page-cache": false,
"chromium-args": "--disable-setuid-sandbox"
"chromium-args": "--disable-setuid-sandbox",
"single-instance": true
}
......@@ -21,6 +21,8 @@ var DEBUG = true;
var fs = require('fs');
var cnf = JSON.parse(fs.readFileSync(gui.App.argv[0], encoding='utf-8'));
function log_debug(msg) { if (DEBUG) console.log(msg); }
function send_json(socket, msg) {
socket.send(JSON.stringify(msg));
}
......@@ -46,16 +48,20 @@ function post_ui_id(socket) {
function post_shutdown(socket) {
send_json(socket, {'method': 'post', 'path': 'shutdown'});
log_debug('Close all windows');
closeWindows();
log_debug('Close socket');
socket.close();
log_debug('Shutdown is complete');
} // expected response: nothing
function post_pause(socket) {
if (DEBUG) console.log('SEND post pause');
log_debug('SEND post pause');
send_json(socket, {'method': 'post', 'path': 'pause'});
} // expected response: {"OK": 200}
function post_start(socket) {
if (DEBUG) console.log('SEND post start');
log_debug('SEND post start');
send_json(socket, {'method': 'post', 'path': 'start'});
} // expected response: {"OK": 200}
......@@ -77,12 +83,12 @@ function get_status(socket) {
// Connect to helper
var socket = new WebSocket(cnf['address']);
socket.onopen = function() {
if (DEBUG) console.log('Send GUI ID to helper');
log_debug('Send GUI ID to helper');
post_ui_id(this);
}
socket.onmessage = function(e) {
var r = JSON.parse(e.data)
if (DEBUG) console.log('RECV: ' + r['action'])
log_debug('RECV: ' + r['action'])
switch(r['action']) {
case 'post ui_id':
if (r['ACCEPTED'] === 202) {
......@@ -91,28 +97,28 @@ socket.onmessage = function(e) {
globals.authenticated = true;
globals.just_opened = true;
} else {
if (DEBUG) console.log('Helper: ' + JSON.stringify(r));
log_debug('Helper: ' + JSON.stringify(r));
closeWindows();
}
break;
case 'post start':
case 'post pause':
if (DEBUG) console.log('RECV ' + r['OK']);
log_debug('RECV ' + r['OK']);
if (r['OK'] === 200) {
get_status(this);
} else {
if (DEBUG) console.log('Helper: ' + JSON.stringify(r));
log_debug('Helper: ' + JSON.stringify(r));
}
break;
case 'get settings':
if (DEBUG) console.log(r);
log_debug(r);
globals['settings'] = r;
break;
case 'put settings':
if (r['CREATED'] === 201) {
get_settings(this);
} else {
if (DEBUG) console.log('Helper: ' + JSON.stringify(r));
log_debug('Helper: ' + JSON.stringify(r));
}
break;
case 'get status':
......@@ -132,6 +138,6 @@ socket.onerror = function (e) {
closeWindows();
}
socket.onclose = function() {
if (DEBUG) console.log('Connection to helper closed');
log_debug('Connection to helper closed');
closeWindows();
}
......@@ -113,7 +113,7 @@ class WebSocketProtocol(WebSocket):
-- INTERRNAL HANDSAKE --
GUI: {"method": "post", "ui_id": <GUI ID>}
HELPER: {"ACCEPTED": 202, "method": "post"}" or
HELPER: {"ACCEPTED": 202, "action": "post ui_id"}" or
"{"REJECTED": 401, "action": "post ui_id"}
-- SHUT DOWN --
......@@ -224,7 +224,8 @@ class WebSocketProtocol(WebSocket):
except Exception:
self.settings['url'] = None
for option in ('container', 'directory', 'exclude'):
# for option in ('container', 'directory', 'exclude'):
for option in ('container', 'directory'):
try:
self.settings[option] = self.cnf.get_sync(sync, option)
except KeyError:
......@@ -257,7 +258,8 @@ class WebSocketProtocol(WebSocket):
self.cnf.set_cloud(cloud, 'token', self.settings['token'] or '')
self.cnf.set_sync(sync, 'cloud', cloud)
for option in ('directory', 'container', 'exclude'):
# for option in ('directory', 'container', 'exclude'):
for option in ('directory', 'container'):
self.cnf.set_sync(sync, option, self.settings[option] or '')
self.cnf.write()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment