Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit a576485df5620566b780eb4fa0820225e004863f

Avoiding bloat for partial ownloads
  
3838from sugar.graphics.icon import Icon
3939from sugar.graphics import style
4040from sugar.activity import activity
41
4241# #3903 - this constant can be removed and assumed to be 1 when dbus-python
4342# 0.82.3 is the only version used
4443import dbus
6767def remove_all_downloads():
6868 for download in _active_downloads:
6969 download.cancelable.cancel(NS_ERROR_FAILURE)
70 download._delete_partial_download()
7071 if download.dl_jobject is not None:
7172 download.datastore_deleted_handler.remove()
7273 datastore.delete(download.dl_jobject.object_id)
166166 _active_downloads.append(self)
167167
168168 elif state_flags & interfaces.nsIWebProgressListener.STATE_STOP:
169 if NS_FAILED(status): # download cancelled
170 return
169 if NS_FAILED(status):
170 self._delete_partial_download() # download cancelled
171 return
171172
172173 self._stop_alert = Alert()
173174 self._stop_alert.props.title = _('Download completed')
245245 preview_data = ''.join(preview_data)
246246 return dbus.ByteArray(preview_data)
247247
248 def _delete_partial_download(self):
249 file_path = self._target_file.path.encode('utf-8', 'replace')
250 if os.path.exists(file_path):
251 os.unlink(file_path)
252 if os.path.exists(file_path + ".part"):
253 os.unlink(file_path + ".part")
254
248255 def __start_response_cb(self, alert, response_id):
249256 global _active_downloads
250257 if response_id is gtk.RESPONSE_CANCEL:
251258 logging.debug('Download Canceled')
259 self._delete_partial_download()
252260 self.cancelable.cancel(NS_ERROR_FAILURE)
253261 try:
254262 self.datastore_deleted_handler.remove()
281281 global _active_downloads
282282 _active_downloads.remove(self)
283283
284 file_path = self._target_file.path.encode('utf-8', 'replace')
284285 if os.path.isfile(self.dl_jobject.file_path):
285286 os.remove(self.dl_jobject.file_path)
286287 self.dl_jobject.destroy()
353353 global _active_downloads
354354 if self in _active_downloads:
355355 # TODO: Use NS_BINDING_ABORTED instead of NS_ERROR_FAILURE.
356 self._delete_partial_download()
356357 self.cancelable.cancel(NS_ERROR_FAILURE) #NS_BINDING_ABORTED)
357358 _active_downloads.remove(self)
358359