1
# -*- coding: utf-8 -*-
3
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
5
# Copyright 2011 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""The syncdaemon client."""
24
from ubuntuone.controlpanel.logger import setup_logging
26
# pylint: disable=W0611
29
logger = setup_logging('sd_client')
32
def get_syncdaemon_tool():
33
"""Get a proxy for the SyncDaemonTool."""
34
# Reimport 'SyncDaemonTool'
35
# No name 'tools' in module 'ubuntuone.platform'
36
# pylint: disable=W0404, E0611
37
from ubuntuone.platform import tools
38
proxy = tools.SyncDaemonTool()
42
def get_throttling_limits():
43
"""Get the speed limits from the syncdaemon."""
44
return get_syncdaemon_tool().get_throttling_limits()
47
def set_throttling_limits(limits):
48
"""Set the speed limits on the syncdaemon."""
49
dload = int(limits["download"])
50
uload = int(limits["upload"])
51
return get_syncdaemon_tool().set_throttling_limits(dload, uload)
54
def bandwidth_throttling_enabled():
55
"""Get the state of throttling in the syncdaemon."""
56
return get_syncdaemon_tool().is_throttling_enabled()
59
def enable_bandwidth_throttling():
60
"""Enable the speed limits in the syncdaemon."""
61
return get_syncdaemon_tool().enable_throttling(True)
64
def disable_bandwidth_throttling():
65
"""Disable the speed limits in the syncdaemon."""
66
return get_syncdaemon_tool().enable_throttling(False)
69
def autoconnect_enabled():
70
"""Get the state of autoconnect in the syncdaemon."""
71
return get_syncdaemon_tool().is_autoconnect_enabled()
74
def enable_autoconnect():
75
"""Enable autoconnect in the syncdaemon."""
76
return get_syncdaemon_tool().enable_autoconnect(True)
79
def disable_autoconnect():
80
"""Disable autoconnect in the syncdaemon."""
81
return get_syncdaemon_tool().enable_autoconnect(False)
84
def show_all_notifications_enabled():
85
"""Get the state of show_all_notifications in the syncdaemon."""
86
return get_syncdaemon_tool().is_show_all_notifications_enabled()
89
def enable_show_all_notifications():
90
"""Enable show_all_notifications in the syncdaemon."""
91
return get_syncdaemon_tool().enable_show_all_notifications(True)
94
def disable_show_all_notifications():
95
"""Disable show_all_notifications in the syncdaemon."""
96
return get_syncdaemon_tool().enable_show_all_notifications(False)
99
def share_autosubscribe_enabled():
100
"""Get the state of share_autosubscribe in the syncdaemon."""
101
return get_syncdaemon_tool().is_share_autosubscribe_enabled()
104
def enable_share_autosubscribe():
105
"""Enable share_autosubscribe in the syncdaemon."""
106
return get_syncdaemon_tool().enable_share_autosubscribe(True)
109
def disable_share_autosubscribe():
110
"""Disable share_autosubscribe in the syncdaemon."""
111
return get_syncdaemon_tool().enable_share_autosubscribe(False)
114
def udf_autosubscribe_enabled():
115
"""Get the state of udf_autosubscribe in the syncdaemon."""
116
return get_syncdaemon_tool().is_udf_autosubscribe_enabled()
119
def enable_udf_autosubscribe():
120
"""Enable udf_autosubscribe in the syncdaemon."""
121
return get_syncdaemon_tool().enable_udf_autosubscribe(True)
124
def disable_udf_autosubscribe():
125
"""Disable udf_autosubscribe in the syncdaemon."""
126
return get_syncdaemon_tool().enable_udf_autosubscribe(False)
130
"""Retrieve the root information from syncdaemon."""
131
return get_syncdaemon_tool().get_root_dir()
134
def get_shares_dir():
135
"""Retrieve the shares information from syncdaemon."""
136
return get_syncdaemon_tool().get_shares_dir()
139
def get_shares_dir_link():
140
"""Retrieve the shares information from syncdaemon."""
141
return get_syncdaemon_tool().get_shares_dir_link()
145
"""Retrieve the folders information from syncdaemon."""
146
return get_syncdaemon_tool().get_folders()
149
def create_folder(path):
150
"""Create a new folder through syncdaemon."""
151
return get_syncdaemon_tool().create_folder(path)
154
def subscribe_folder(folder_id):
155
"""Subscribe to 'folder_id'."""
156
return get_syncdaemon_tool().subscribe_folder(folder_id)
159
def unsubscribe_folder(folder_id):
160
"""Unsubscribe 'folder_id'."""
161
return get_syncdaemon_tool().unsubscribe_folder(folder_id)
165
"""Retrieve the shares information from syncdaemon."""
166
return get_syncdaemon_tool().get_shares()
169
def subscribe_share(share_id):
170
"""Subscribe to 'share_id'."""
171
return get_syncdaemon_tool().subscribe_share(share_id)
174
def unsubscribe_share(share_id):
175
"""Unsubscribe 'share_id'."""
176
return get_syncdaemon_tool().unsubscribe_share(share_id)
179
def get_current_status():
180
"""Retrieve the current status from syncdaemon."""
181
return get_syncdaemon_tool().get_status()
184
def file_sync_enabled():
185
"""Get if file sync service is enabled."""
186
return get_syncdaemon_tool().is_files_sync_enabled()
189
def enable_file_sync():
190
"""Enable the file sync service."""
191
return get_syncdaemon_tool().enable_files_sync(True)
194
def disable_file_sync():
195
"""Enable the file sync service."""
196
return get_syncdaemon_tool().enable_files_sync(False)
199
def files_sync_enabled():
200
"""Get if file sync service is enabled."""
201
warnings.warn('use file_sync_enabled instead', DeprecationWarning)
202
return file_sync_enabled()
205
def set_files_sync_enabled(enabled):
206
"""Set the file sync service to be 'enabled'."""
207
warnings.warn('use {enable/disable}_file_sync instead', DeprecationWarning)
209
return enable_file_sync()
211
return disable_file_sync()
214
def connect_file_sync():
215
"""Connect the file sync service."""
216
return get_syncdaemon_tool().connect()
219
def disconnect_file_sync():
220
"""Disconnect the file sync service."""
221
return get_syncdaemon_tool().disconnect()
224
def start_file_sync():
225
"""Start the file sync service."""
226
return get_syncdaemon_tool().start()
229
def stop_file_sync():
230
"""Stop the file sync service."""
231
return get_syncdaemon_tool().quit()
234
if sys.platform.startswith("linux"):
235
from ubuntuone.controlpanel.sd_client.linux \
236
import set_status_changed_handler
239
def set_status_changed_handler(handler):
240
"""Set the status handler function."""
241
return get_syncdaemon_tool().set_status_changed_handler(handler)