26
26
from ubuntuone.controlpanel import dbus_client
27
27
from ubuntuone.controlpanel import replication_client
28
28
from ubuntuone.controlpanel.logger import setup_logging, log_call
29
from ubuntuone.controlpanel.webclient import WebClient
29
from ubuntuone.controlpanel.webclient import WebClient, WebClientError
32
32
logger = setup_logging('backend')
143
143
_set_status_changed_handler)
146
def _process_device_web_info(self, devices, enabled, limit_bw, limits,
148
"""Return a lis of processed devices."""
152
di["type"] = d["kind"]
153
di["name"] = d["description"]
154
di["configurable"] = ''
155
if di["type"] == DEVICE_TYPE_COMPUTER:
156
di["device_id"] = di["type"] + d["token"]
157
if di["type"] == DEVICE_TYPE_PHONE:
158
di["device_id"] = di["type"] + str(d["id"])
160
is_local = yield self.device_is_local(di["device_id"])
161
di["is_local"] = bool_str(is_local)
162
# currently, only local devices are configurable.
163
# eventually, more devices will be configurable.
164
di["configurable"] = bool_str(is_local and enabled)
166
if bool(di["configurable"]):
167
di["limit_bandwidth"] = bool_str(limit_bw)
168
di["show_all_notifications"] = bool_str(show_notifs)
169
upload = limits["upload"]
170
download = limits["download"]
171
di[UPLOAD_KEY] = str(upload)
172
di[DOWNLOAD_KEY] = str(download)
174
# date_added is not in the webservice yet (LP: #673668)
175
# di["date_added"] = ""
177
# missing values (LP: #673668)
178
# di["available_services"] = ""
179
# di["enabled_services"] = ""
181
if is_local: # prepend the local device!
146
189
def get_token(self):
147
190
"""Return the token from the credentials."""
148
191
credentials = yield dbus_client.get_credentials()
189
232
def devices_info(self):
190
233
"""Get the user devices info."""
192
limit_bw = yield dbus_client.bandwidth_throttling_enabled()
193
show_all_notif = yield dbus_client.show_all_notifications_enabled()
194
limits = yield dbus_client.get_throttling_limits()
196
devices = yield self.wc.call_api(DEVICES_API)
199
di["type"] = d["kind"]
200
di["name"] = d["description"]
201
di["configurable"] = ''
202
if di["type"] == DEVICE_TYPE_COMPUTER:
203
di["device_id"] = di["type"] + d["token"]
204
if di["type"] == DEVICE_TYPE_PHONE:
205
di["device_id"] = di["type"] + str(d["id"])
207
is_local = yield self.device_is_local(di["device_id"])
208
di["is_local"] = bool_str(is_local)
209
# currently, only local devices are configurable.
210
# eventually, more the devices will be configurable.
211
di["configurable"] = bool_str(is_local)
213
if bool(di["configurable"]):
214
di["limit_bandwidth"] = bool_str(limit_bw)
215
di["show_all_notifications"] = bool_str(show_all_notif)
234
result = limit_bw = limits = show_notifs = None
235
enabled = yield dbus_client.files_sync_enabled()
237
limit_bw = yield dbus_client.bandwidth_throttling_enabled()
238
show_notifs = yield dbus_client.show_all_notifications_enabled()
239
limits = yield dbus_client.get_throttling_limits()
242
devices = yield self.wc.call_api(DEVICES_API)
243
except WebClientError:
244
logger.exception('devices_info: web client failure:')
246
result = yield self._process_device_web_info(devices, enabled,
250
credentials = yield dbus_client.get_credentials()
252
local_device["type"] = DEVICE_TYPE_COMPUTER
253
local_device["name"] = credentials['name']
254
device_id = local_device["type"] + credentials["token"]
255
local_device["device_id"] = device_id
256
local_device["is_local"] = bool_str(True)
257
local_device["configurable"] = bool_str(enabled)
258
if bool(local_device["configurable"]):
259
local_device["limit_bandwidth"] = bool_str(limit_bw)
260
show_notifs = bool_str(show_notifs)
261
local_device["show_all_notifications"] = show_notifs
216
262
upload = limits["upload"]
217
263
download = limits["download"]
218
di[UPLOAD_KEY] = str(upload)
219
di[DOWNLOAD_KEY] = str(download)
221
# date_added is not in the webservice yet (LP: #673668)
222
# di["date_added"] = ""
224
# missing values (LP: #673668)
225
# di["available_services"] = ""
226
# di["enabled_services"] = ""
228
if is_local: # prepend the local device!
264
local_device[UPLOAD_KEY] = str(upload)
265
local_device[DOWNLOAD_KEY] = str(download)
266
result = [local_device]
233
268
returnValue(result)