From 97943414dae6ec39716d3a33591792fecf2605d6 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 16 May 2007 04:42:28 +0000 Subject: Do datastore ops async --- (limited to 'webactivity.py') diff --git a/webactivity.py b/webactivity.py index 93c33f8..20b49b2 100755 --- a/webactivity.py +++ b/webactivity.py @@ -146,12 +146,10 @@ def download_started_cb(download_manager, download): 'file://' + download.get_file_name(), on_disk = True) -def download_completed_cb(download_manager, download): - jobject = datastore.get(download.get_data('jobject-id')) - jobject['title'] = _('File %s downloaded from\n%s.') % \ - (get_download_file_name(download), download.get_url()) - jobject.file_path = download.get_file_name() - datastore.write(jobject) +def _dl_completed_cb(download, success, err=None): + if not success: + # Log errors but still set object completed + logging.debug("Error writing completed download to datastore: %s" % err) object_id = download.get_data('object-id') if not object_id: @@ -160,12 +158,29 @@ def download_completed_cb(download_manager, download): cb_service = clipboardservice.get_instance() cb_service.set_object_percent(object_id, 100) +def download_completed_cb(download_manager, download): + jobject = datastore.get(download.get_data('jobject-id')) + jobject['title'] = _('File %s downloaded from\n%s.') % \ + (get_download_file_name(download), download.get_url()) + jobject.file_path = download.get_file_name() + datastore.write(jobject, + reply_handler=lambda *args: _dl_completed_cb(download, True, *args), + error_handler=lambda *args: _dl_completed_cb(download, False, *args)) + def download_cancelled_cb(download_manager, download): #FIXME: Needs to update the state of the object to 'download stopped'. #FIXME: Will do it when we complete progress on the definition of the #FIXME: clipboard API. raise "Cancelling downloads still not implemented." +def _dl_progress_cb(download, percent, success, err=None): + if not success: + # Log errors but still set object completed + logging.debug("Error writing completed download to datastore: %s" % err) + + cb_service = clipboardservice.get_instance() + cb_service.set_object_percent(download.get_data('object-id'), percent) + def download_progress_cb(download_manager, download): object_id = download.get_data('jobject-id') if not object_id: @@ -176,12 +191,9 @@ def download_progress_cb(download_manager, download): # from download_completed_cb instead percent = download.get_percent() if percent < 100: - """ jobject = datastore.get(download.get_data('jobject-id')) jobject['title'] = _('Downloading %s from\n%s.\nProgress %i%%.') % \ (get_download_file_name(download), download.get_url(), percent) - datastore.write(jobject) - """ - - cb_service = clipboardservice.get_instance() - cb_service.set_object_percent(download.get_data('object-id'), percent) + datastore.write(jobject, + reply_handler=lambda *args: _dl_progress_cb(download, percent, True, *args), + error_handler=lambda *args: _dl_progress_cb(download, percent, False, *args)) -- cgit v0.9.1