protocol.py 1.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from ws4py.websocket import WebSocket


class WebSocketProtocol(WebSocket):
    """Helper-side WebSocket protocol for communication with GUI:

    -- INTERRNAL HANDSAKE --
    GUI: {"token": <token>}
    HELPER: {"ACCEPTED": 202}" or "{"ERROR": 401, "MESSAGE": <message>}

    -- GET SETTINGS --
    GUI: {"method": "get", "path": "settings"}
    HELPER:
        {
            "token": <user token>,
            "url": <auth url>,
            "container": <container>,
            "directory": <local directory>,
            "exclude": <file path>
        } or {"ERROR": <error code>, "MESSAGE": <message>}"

    -- PUT SETTINGS --
    GUI: {
            "method": "put", "path": "settings",
            "token": <user token>,
            "url": <auth url>,
            "container": <container>,
            "directory": <local directory>,
            "exclude": <file path>
        }
    HELPER: {"CREATED": 201} or {"ERROR": <error code>, "MESSAGE": <message>}

    -- GET STATUS --
    GUI: {"method": "get", "path": "status"}
    HELPER: ""progres": <int>, "paused": <boolean>} or
        {"ERROR": <error code>, "MESSAGE": <message>}
    """

    def __init__(self, *args, **kwargs):
        super(WebSocketProtocol, self).__init__(*args, **kwargs)
        print 'lala'