~dobey/ubuntu/oneiric/ubuntuone-control-panel/release-113

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/sd_client/__init__.py

  • Committer: Sebastien Bacher
  • Date: 2011-07-25 13:17:38 UTC
  • mfrom: (25.1.2 ubuntuone-control-panel)
  • Revision ID: seb128@ubuntu.com-20110725131738-yuevatnd859d1phs
Tags: 1.1.1-0ubuntu1
releasing version 1.1.1-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
 
4
#
 
5
# Copyright 2011 Canonical Ltd.
 
6
#
 
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.
 
10
#
 
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.
 
15
#
 
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/>.
 
18
 
 
19
"""The syncdaemon client."""
 
20
 
 
21
import sys
 
22
import warnings
 
23
 
 
24
from ubuntuone.controlpanel.logger import setup_logging
 
25
 
 
26
# pylint: disable=W0611
 
27
 
 
28
 
 
29
logger = setup_logging('sd_client')
 
30
 
 
31
 
 
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()
 
39
    return proxy
 
40
 
 
41
 
 
42
def get_throttling_limits():
 
43
    """Get the speed limits from the syncdaemon."""
 
44
    return get_syncdaemon_tool().get_throttling_limits()
 
45
 
 
46
 
 
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)
 
52
 
 
53
 
 
54
def bandwidth_throttling_enabled():
 
55
    """Get the state of throttling in the syncdaemon."""
 
56
    return get_syncdaemon_tool().is_throttling_enabled()
 
57
 
 
58
 
 
59
def enable_bandwidth_throttling():
 
60
    """Enable the speed limits in the syncdaemon."""
 
61
    return get_syncdaemon_tool().enable_throttling(True)
 
62
 
 
63
 
 
64
def disable_bandwidth_throttling():
 
65
    """Disable the speed limits in the syncdaemon."""
 
66
    return get_syncdaemon_tool().enable_throttling(False)
 
67
 
 
68
 
 
69
def autoconnect_enabled():
 
70
    """Get the state of autoconnect in the syncdaemon."""
 
71
    return get_syncdaemon_tool().is_autoconnect_enabled()
 
72
 
 
73
 
 
74
def enable_autoconnect():
 
75
    """Enable autoconnect in the syncdaemon."""
 
76
    return get_syncdaemon_tool().enable_autoconnect(True)
 
77
 
 
78
 
 
79
def disable_autoconnect():
 
80
    """Disable autoconnect in the syncdaemon."""
 
81
    return get_syncdaemon_tool().enable_autoconnect(False)
 
82
 
 
83
 
 
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()
 
87
 
 
88
 
 
89
def enable_show_all_notifications():
 
90
    """Enable show_all_notifications in the syncdaemon."""
 
91
    return get_syncdaemon_tool().enable_show_all_notifications(True)
 
92
 
 
93
 
 
94
def disable_show_all_notifications():
 
95
    """Disable show_all_notifications in the syncdaemon."""
 
96
    return get_syncdaemon_tool().enable_show_all_notifications(False)
 
97
 
 
98
 
 
99
def share_autosubscribe_enabled():
 
100
    """Get the state of share_autosubscribe in the syncdaemon."""
 
101
    return get_syncdaemon_tool().is_share_autosubscribe_enabled()
 
102
 
 
103
 
 
104
def enable_share_autosubscribe():
 
105
    """Enable share_autosubscribe in the syncdaemon."""
 
106
    return get_syncdaemon_tool().enable_share_autosubscribe(True)
 
107
 
 
108
 
 
109
def disable_share_autosubscribe():
 
110
    """Disable share_autosubscribe in the syncdaemon."""
 
111
    return get_syncdaemon_tool().enable_share_autosubscribe(False)
 
112
 
 
113
 
 
114
def udf_autosubscribe_enabled():
 
115
    """Get the state of udf_autosubscribe in the syncdaemon."""
 
116
    return get_syncdaemon_tool().is_udf_autosubscribe_enabled()
 
117
 
 
118
 
 
119
def enable_udf_autosubscribe():
 
120
    """Enable udf_autosubscribe in the syncdaemon."""
 
121
    return get_syncdaemon_tool().enable_udf_autosubscribe(True)
 
122
 
 
123
 
 
124
def disable_udf_autosubscribe():
 
125
    """Disable udf_autosubscribe in the syncdaemon."""
 
126
    return get_syncdaemon_tool().enable_udf_autosubscribe(False)
 
127
 
 
128
 
 
129
def get_root_dir():
 
130
    """Retrieve the root information from syncdaemon."""
 
131
    return get_syncdaemon_tool().get_root_dir()
 
132
 
 
133
 
 
134
def get_shares_dir():
 
135
    """Retrieve the shares information from syncdaemon."""
 
136
    return get_syncdaemon_tool().get_shares_dir()
 
137
 
 
138
 
 
139
def get_shares_dir_link():
 
140
    """Retrieve the shares information from syncdaemon."""
 
141
    return get_syncdaemon_tool().get_shares_dir_link()
 
142
 
 
143
 
 
144
def get_folders():
 
145
    """Retrieve the folders information from syncdaemon."""
 
146
    return get_syncdaemon_tool().get_folders()
 
147
 
 
148
 
 
149
def create_folder(path):
 
150
    """Create a new folder through syncdaemon."""
 
151
    return get_syncdaemon_tool().create_folder(path)
 
152
 
 
153
 
 
154
def subscribe_folder(folder_id):
 
155
    """Subscribe to 'folder_id'."""
 
156
    return get_syncdaemon_tool().subscribe_folder(folder_id)
 
157
 
 
158
 
 
159
def unsubscribe_folder(folder_id):
 
160
    """Unsubscribe 'folder_id'."""
 
161
    return get_syncdaemon_tool().unsubscribe_folder(folder_id)
 
162
 
 
163
 
 
164
def get_shares():
 
165
    """Retrieve the shares information from syncdaemon."""
 
166
    return get_syncdaemon_tool().get_shares()
 
167
 
 
168
 
 
169
def subscribe_share(share_id):
 
170
    """Subscribe to 'share_id'."""
 
171
    return get_syncdaemon_tool().subscribe_share(share_id)
 
172
 
 
173
 
 
174
def unsubscribe_share(share_id):
 
175
    """Unsubscribe 'share_id'."""
 
176
    return get_syncdaemon_tool().unsubscribe_share(share_id)
 
177
 
 
178
 
 
179
def get_current_status():
 
180
    """Retrieve the current status from syncdaemon."""
 
181
    return get_syncdaemon_tool().get_status()
 
182
 
 
183
 
 
184
def file_sync_enabled():
 
185
    """Get if file sync service is enabled."""
 
186
    return get_syncdaemon_tool().is_files_sync_enabled()
 
187
 
 
188
 
 
189
def enable_file_sync():
 
190
    """Enable the file sync service."""
 
191
    return get_syncdaemon_tool().enable_files_sync(True)
 
192
 
 
193
 
 
194
def disable_file_sync():
 
195
    """Enable the file sync service."""
 
196
    return get_syncdaemon_tool().enable_files_sync(False)
 
197
 
 
198
 
 
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()
 
203
 
 
204
 
 
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)
 
208
    if enabled:
 
209
        return enable_file_sync()
 
210
    else:
 
211
        return disable_file_sync()
 
212
 
 
213
 
 
214
def connect_file_sync():
 
215
    """Connect the file sync service."""
 
216
    return get_syncdaemon_tool().connect()
 
217
 
 
218
 
 
219
def disconnect_file_sync():
 
220
    """Disconnect the file sync service."""
 
221
    return get_syncdaemon_tool().disconnect()
 
222
 
 
223
 
 
224
def start_file_sync():
 
225
    """Start the file sync service."""
 
226
    return get_syncdaemon_tool().start()
 
227
 
 
228
 
 
229
def stop_file_sync():
 
230
    """Stop the file sync service."""
 
231
    return get_syncdaemon_tool().quit()
 
232
 
 
233
 
 
234
if sys.platform.startswith("linux"):
 
235
    from ubuntuone.controlpanel.sd_client.linux \
 
236
    import set_status_changed_handler
 
237
else:
 
238
 
 
239
    def set_status_changed_handler(handler):
 
240
        """Set the status handler function."""
 
241
        return get_syncdaemon_tool().set_status_changed_handler(handler)