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

Move notification messages to UI data folder

Notification messages should not be stated inline, but loaded from
external data files. For that purpose, a new directory "ui_data"
is created, to store data files for the UI.

Currently, there is just one data file "common.json", containing
as dictionary of protocol statuses and corresponding notifications.
parent 986bcb0e
......@@ -21,20 +21,7 @@ from agkyra import config, protocol, protocol_client
LOG = logging.getLogger(__name__)
STATUS = protocol.STATUS
NOTIFICATION = {
0: 'Not initialized',
1: 'Initializing ...',
2: 'Shutting down',
100: 'Syncing',
101: 'Pausing',
102: 'Paused',
200: 'Settings are incomplete',
201: 'Cloud URL error',
202: 'Authentication error',
203: 'Local directory error',
204: 'Remote container error',
1000: 'Critical error'
}
NOTIFICATION = protocol.COMMON['NOTIFICATION']
remaining = lambda st: st['unsynced'] - (st['synced'] + st['failed'])
......
var gui = require('nw.gui');
var NOTIFICATION = {
0: 'Not initialized',
1: 'Initializing ...',
2: 'Shutting down',
100: 'Syncing',
101: 'Pausing',
102: 'Paused',
200: 'Settings are incomplete',
201: 'Cloud URL error',
202: 'Authentication error',
203: 'Local directory error',
204: 'Remote container error',
1000: 'error error'
}
function is_up(code) { return (code / 100 >> 0) === 1; }
function has_settings_error(code) { return (code / 200 >> 0) === 2; }
function remaining(status) {
......
......@@ -21,7 +21,10 @@ var fs = require('fs');
// Read config file
var cnf = JSON.parse(fs.readFileSync(gui.App.argv[0], encoding='utf-8'));
var UI_COMMON = JSON.parse(fs.readFileSync(path.join('..', 'ui_common.json')));
var COMMON = JSON.parse(fs.readFileSync(path.join('..', 'ui_data/common.json')));
var STATUS = COMMON['STATUS'];
var NOTIFICATION = COMMON['NOTIFICATION'];
function log_debug(msg) { if (DEBUG) console.log(msg); }
......@@ -29,8 +32,6 @@ function send_json(socket, msg) {
socket.send(JSON.stringify(msg));
}
var STATUS = UI_COMMON['STATUS'];
var globals = {
settings: {
token: null,
......
......@@ -34,9 +34,9 @@ CURPATH = os.path.dirname(os.path.abspath(__file__))
LOG = logging.getLogger(__name__)
SYNCERS = utils.ThreadSafeDict()
with open(os.path.join(CURPATH, 'ui_common.json')) as f:
UI_COMMON = json.load(f)
STATUS = UI_COMMON['STATUS']
with open(os.path.join(CURPATH, 'ui_data/common.json')) as f:
COMMON = json.load(f)
STATUS = COMMON['STATUS']
def retry_on_locked_db(method, *args, **kwargs):
......@@ -446,13 +446,13 @@ class WebSocketProtocol(WebSocket):
# d.update(unsynced=0, synced=0, failed=0)
while msg:
if isinstance(msg, messaging.SyncMessage):
LOG.error('UNSYNCED +1')
LOG.error('UNSYNCED +1 %s' % getattr(msg, 'objname', ''))
self.set_status(unsynced=self.get_status('unsynced') + 1)
elif isinstance(msg, messaging.AckSyncMessage):
LOG.error('SYNCED +1')
LOG.error('SYNCED +1 %s' % getattr(msg, 'objname', ''))
self.set_status(synced=self.get_status('synced') + 1)
elif isinstance(msg, messaging.SyncErrorMessage):
LOG.error('FAILED +1')
LOG.error('FAILED +1 %s' % getattr(msg, 'objname', ''))
self.set_status(failed=self.get_status('failed') + 1)
elif isinstance(msg, messaging.LocalfsSyncDisabled):
self.set_status(code=STATUS['DIRECTORY ERROR'])
......
......@@ -12,5 +12,19 @@
"DIRECTORY ERROR": 203,
"CONTAINER ERROR": 204,
"CRITICAL ERROR": 1000
}
},
"NOTIFICATION": {
"0": "Not initialized",
"1": "Initializing ...",
"2": "Shutting down",
"100": "Syncing",
"101": "Pausing",
"102": "Paused",
"200": "Settings are incomplete",
"201": "Cloud URL error",
"202": "Authentication error",
"203": "Local directory error",
"204": "Remote container error",
"1000": "Critical error"
}
}
\ No newline at end of file
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