Commit 6b78346d authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Report progress as #synced/#unsynced cases

The mechanism is based on syncing message consumption, which works
only while the client is syncing (therefore, not in paused mode).

When GUI consumes a "SyncMessage", an "unsynced" counter is
increased, while a "AckSyncMessage" causes a "synced" counter to
increase. The two counters are pushed to GUI regularly enough.
parent 152cc8b0
......@@ -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;
......
......@@ -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
......
......@@ -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
{
......
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