~facundo/magicicada-client/new-trash

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/config.py

  • Committer: Magicicada Bot
  • Author(s): Facundo Batista
  • Date: 2017-03-19 13:22:22 UTC
  • mfrom: (1433.1.4 connect-multi-server)
  • Revision ID: magicicada_bot-20170319132222-07fplgj9qoe1lglb
[r=nataliabidart] Allow in the config multiple servers to connect.

These possible multiple servers travel in one simple object, not a miriad of parameters to ActionQueue, which will use them to try to connect. It first tries the first one, on connection error tries the second, and so on until the list ends, and starts again with the first one.

For a quick retry on different servers, I lowered the initial delay to reconnect to 200ms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# ubuntuone.syncdaemon.config - SyncDaemon config utilities
2
2
#
3
3
# Copyright 2009-2012 Canonical Ltd.
 
4
# Copyright 2017 Chicharreros (https://launchpad.net/~chicharreros)
4
5
#
5
6
# This program is free software: you can redistribute it and/or modify it
6
7
# under the terms of the GNU General Public License version 3, as published
128
129
    return result
129
130
 
130
131
 
 
132
def server_connection_parser(value):
 
133
    """Parser for the server connection info."""
 
134
    results = []
 
135
    for item in value.split(","):
 
136
        ci_parts = item.split(':')
 
137
        if len(ci_parts) == 2:
 
138
            host, port = ci_parts
 
139
            mode = 'ssl'  # default
 
140
        elif len(ci_parts) == 3:
 
141
            host, port, mode = ci_parts
 
142
        else:
 
143
            raise ValueError(
 
144
                "--server info must be HOST:PORT or HOST:PORT:SSL_MODE")
 
145
 
 
146
        if mode == 'plain':
 
147
            use_ssl = False
 
148
            disable_ssl_verify = False
 
149
        elif mode == 'ssl':
 
150
            use_ssl = True
 
151
            disable_ssl_verify = False
 
152
        elif mode == 'ssl_noverify':
 
153
            use_ssl = True
 
154
            disable_ssl_verify = True
 
155
        else:
 
156
            raise ValueError(
 
157
                "--server form (HOST:PORT:SSL_MODE) accepts the following"
 
158
                "SSL_MODE options only: 'plain', 'ssl', 'ssl_noverify'")
 
159
        results.append({
 
160
            'host': host,
 
161
            'port': int(port),
 
162
            'use_ssl': use_ssl,
 
163
            'disable_ssl_verify': disable_ssl_verify,
 
164
        })
 
165
    return results
 
166
 
 
167
 
131
168
def log_level_parser(value):
132
169
    """Parser for "logging" module log levels.
133
170
 
157
194
            ('xdg_cache', xdg_cache_dir_parser),
158
195
            ('xdg_data', xdg_data_dir_parser),
159
196
            ('log_level', log_level_parser),
 
197
            ('connection', server_connection_parser),
160
198
            ('throttling_limit', throttling_limit_parser)]
161
199
 
162
200