diff --git a/agkyra/agkyra/gui/menu.html b/agkyra/agkyra/gui/menu.html index 383bb74ee2802210f3895d643b7a5b70a7c6861f..daeadb64e368635336c76e676576e02db4f9ff11 100644 --- a/agkyra/agkyra/gui/menu.html +++ b/agkyra/agkyra/gui/menu.html @@ -19,7 +19,6 @@ function closeWindows() { // GUI components var tray = new gui.Tray({ - // tooltip: 'Paused (0% synced)', title: 'Agkyra syncs with Pithos+', icon: 'images/tray.png' }); @@ -165,30 +164,31 @@ window.setInterval(function() { new_progress = 'Incomplete settings' new_pause = 'inactive' pause_item.enabled = false; - } else if (status.paused !== null) { - switch(pause_item.label) { - case pause_syncing: if (status.paused) { - // Update to "Paused - start syncing" - paused = true; - new_pause = start_syncing; + } else { + if (status.paused !== null) { + switch(pause_item.label) { + case pause_syncing: if (status.paused) { + // Update to "Paused - start syncing" + paused = true; + new_pause = start_syncing; + menu_modified = true; + } // else continue syncing + break; + case start_syncing: if (!status.paused) { + //update to "Syncing - pause syncing" + paused = false; + new_pause = pause_syncing; + menu_modified = true; + } + break; + default: + if (status.paused) {new_pause = start_syncing; paused=true;} + else {new_pause = pause_syncing; paused=false;} + pause_item.enabled = true; menu_modified = true; - } // else continue syncing - new_progress = status.progress + '%' + ' synced'; - break; - case start_syncing: if (status.paused) return; - // else update to "Syncing - pause syncing" - paused = false; - new_pause = pause_syncing; - new_progress = status.progress + '%' + ' synced'; - menu_modified = true; - break; - default: - if (status.paused) {new_pause = start_syncing; paused=true;} - else {new_pause = pause_syncing; paused=false;} - new_progress = status.progress + '%' + ' synced'; - pause_item.enabled = true; - menu_modified = true; + } } + new_progress = status.synced + ' of ' + status.unsynced + ' synced'; } if (new_pause != pause_item.label) { pause_item.label = new_pause; diff --git a/agkyra/agkyra/gui/protocol.js b/agkyra/agkyra/gui/protocol.js index e115fb767572e14e15245d021ac089050837198d..4f74de105034672a9dc26dfb7e15c961811745d9 100644 --- a/agkyra/agkyra/gui/protocol.js +++ b/agkyra/agkyra/gui/protocol.js @@ -18,7 +18,7 @@ var globals = { 'directory': null, 'exclude': null }, - 'status': {"progress": null, "paused": null, "can_sync": false}, + 'status': {"synced": 0, "unsynced": 0, "paused": null, "can_sync": false}, 'authenticated': false, } @@ -54,7 +54,7 @@ function put_settings(socket, new_settings) { function get_status(socket) { send_json(socket, {'method': 'get', 'path': 'status'}); -} // expected response {"progress": ..., "paused": ...} +} // expected response {"synced":.., "unsynced":.., "paused":.., "can_sync":..} // Connect to helper diff --git a/agkyra/agkyra/protocol.py b/agkyra/agkyra/protocol.py index a7a1fcb0ea4bca87094e14fe6643ff0630b385f7..a362d490f97b6582e5aa9b82bb86e4cbc2e21335 100644 --- a/agkyra/agkyra/protocol.py +++ b/agkyra/agkyra/protocol.py @@ -2,7 +2,8 @@ from ws4py.websocket import WebSocket import json import logging from os.path import abspath -from agkyra.syncer import syncer, setup, pithos_client, localfs_client +from agkyra.syncer import ( + syncer, setup, pithos_client, localfs_client, messaging) from agkyra.config import AgkyraConfig @@ -68,7 +69,7 @@ class WebSocketProtocol(WebSocket): token=None, url=None, container=None, directory=None, exclude=None) - status = dict(progress=0, paused=True, can_sync=False) + status = dict(progress=0, synced=0, unsynced=0, paused=True, can_sync=False) file_syncer = None cnf = AgkyraConfig() essentials = ('url', 'token', 'container', 'directory') @@ -153,15 +154,38 @@ class WebSocketProtocol(WebSocket): self.cnf.write() LOG.debug('Settings saved') - def can_sync(self): - """Check if settings are enough to setup a syncing proccess""" - return all([self.settings[e] for e in self.essentials]) - def _essentials_changed(self, new_settings): """Check if essential settings have changed in new_settings""" return all([ self.settings[e] == self.settings[e] for e in self.essentials]) + def _update_statistics(self): + """Update statistics by consuming and understanding syncer messages""" + if self.can_sync(): + msg = self.syncer.get_next_message() + if not msg: + if self.status['unsynced'] == self.status['synced']: + self.status['unsynced'] = 0 + self.status['synced'] = 0 + while (msg): + if isinstance(msg, messaging.SyncMessage): + LOG.info('Start syncing "%s"' % msg.objname) + self.status['unsynced'] += 1 + elif isinstance(msg, messaging.AckSyncMessage): + LOG.info('Finished syncing "%s"' % msg.objname) + self.status['synced'] += 1 + elif isinstance(msg, messaging.CollisionMessage): + LOG.info('Collision for "%s"' % msg.objname) + elif isinstance(msg, messaging.ConflictStashMessage): + LOG.info('Conflict for "%s"' % msg.objname) + else: + LOG.debug('Consumed msg %s' % msg) + msg = self.syncer.get_next_message() + + def can_sync(self): + """Check if settings are enough to setup a syncing proccess""" + return all([self.settings[e] for e in self.essentials]) + def init_sync(self): """Initialize syncer""" sync = self._get_default_sync() @@ -178,10 +202,8 @@ class WebSocketProtocol(WebSocket): # Syncer-related methods def get_status(self): - if (self.can_sync()): - LOG.debug('::::::::: %s' % self.syncer.get_next_message()) + self._update_statistics() self.status['paused'] = self.syncer.paused - self.status['progress'] = 50 self.status['can_sync'] = self.can_sync() return self.status @@ -230,6 +252,8 @@ class WebSocketProtocol(WebSocket): if self.accepted: action = r['path'] if action == 'shutdown': + if self.can_sync(): + self.syncer.stop_all_daemons() self.close() return {