[postr] track progress for extra upload steps
- From: Germán Poó Caamaño <gpoo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [postr] track progress for extra upload steps
- Date: Sun, 31 Jan 2010 02:41:44 +0000 (UTC)
commit 219b5185f44e47d1328a208e00bc1785b64e39d4
Author: David Ignacio <dignacio litl com>
Date: Tue Dec 15 20:38:35 2009 -0500
track progress for extra upload steps
after the upload of the photo is finished, there are still 4 potential
extra steps to be performed before continuing to the next photo:
add to set, send to group, set licensing, create new set
this patch causes the image upload progress tracker to reflect these
operations as well
src/postr.py | 12 +++++++++++-
src/proxyclient.py | 26 +++++++++++++++++++++-----
2 files changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/src/postr.py b/src/postr.py
index b41b437..e699404 100644
--- a/src/postr.py
+++ b/src/postr.py
@@ -33,7 +33,7 @@ from AuthenticationDialog import AuthenticationDialog
from ProgressDialog import ProgressDialog
from ErrorDialog import ErrorDialog
import ImageStore, ImageList, StatusBar, PrivacyCombo, SafetyCombo, GroupSelector, ContentTypeCombo
-from proxyclient import UploadProgressTracker
+from proxyclient import EXTRA_STEP_SET_ID, EXTRA_STEP_GROUPS, EXTRA_STEP_LICENSE, EXTRA_STEP_NEW_SET, UploadProgressTracker
from flickrest import Flickr
import EXIF
@@ -901,6 +901,7 @@ class Postr(UniqueApp):
"""Callback from the upload method to add the picture to a set."""
photo_id=rsp.find("photoid").text
self.flickr.photosets_addPhoto(photo_id=photo_id, photoset_id=set).addErrback(self.twisted_error)
+ self.upload_progress_tracker.complete_extra_step(EXTRA_STEP_SET_ID)
return rsp
def add_to_groups(self, rsp, groups):
@@ -912,6 +913,7 @@ class Postr(UniqueApp):
if failure.value.code != 6:
self.twisted_error(failure)
self.flickr.groups_pools_add(photo_id=photo_id, group_id=group).addErrback(error)
+ self.upload_progress_tracker.complete_extra_step(EXTRA_STEP_GROUPS)
return rsp
def set_license(self, rsp, license):
@@ -919,6 +921,7 @@ class Postr(UniqueApp):
photo_id=rsp.find("photoid").text
self.flickr.photos_licenses_setLicense(photo_id=photo_id,
license_id=license).addErrback(self.twisted_error)
+ self.upload_progress_tracker.complete_extra_step(EXTRA_STEP_LICENSE)
return rsp
def upload_done(self):
@@ -1024,16 +1027,23 @@ class Postr(UniqueApp):
if set_id:
d.addCallback(self.add_to_set, set_id)
+ else:
+ self.upload_progress_tracker.complete_extra_step(EXTRA_STEP_SET_ID)
if groups:
d.addCallback(self.add_to_groups, groups)
+ else:
+ self.upload_progress_tracker.complete_extra_step(EXTRA_STEP_GROUPS)
if license is not None: # 0 is a valid license.
d.addCallback(self.set_license, license)
+ else:
+ self.upload_progress_tracker.complete_extra_step(EXTRA_STEP_LICENSE)
# creating a new photoset has implications on subsequent uploads,
# so this has to finish before starting the next upload
if new_photoset_name:
d.addCallback(self.create_photoset_then_continue, new_photoset_name)
else:
d.addCallbacks(self.upload, self.upload_error)
+ self.upload_progress_tracker.complete_extra_step(EXTRA_STEP_NEW_SET)
def create_photoset_then_continue(self, rsp, photoset_name):
photo_id=rsp.find("photoid").text
diff --git a/src/proxyclient.py b/src/proxyclient.py
index 1ff589d..9284c79 100644
--- a/src/proxyclient.py
+++ b/src/proxyclient.py
@@ -416,6 +416,14 @@ def downloadPage(url, file, contextFactory=None, *args, **kwargs):
reactor.connectTCP(host, port, factory)
return factory.deferred
+( EXTRA_STEP_SET_ID,
+ EXTRA_STEP_GROUPS,
+ EXTRA_STEP_LICENSE,
+ EXTRA_STEP_NEW_SET,
+ EXTRA_STEP_NUM_STEPS ) = range(5)
+
+EXTRA_STEP_FRACTION = 0.04
+
class UploadProgressTracker(object):
"""
This object takes a gtk.ProgressBar object as a parameter
@@ -426,11 +434,13 @@ class UploadProgressTracker(object):
self._progress = progress
self._write_size = 1
self._write_progress = 0
+ self._extra_step_progress = 0
def set_write_size(self, size):
"""
Resets the progress count and records the next image's size
"""
+ self._extra_step_progress = 0
self._write_progress = 0
self._write_size = size
@@ -441,18 +451,24 @@ class UploadProgressTracker(object):
def _onConnectionLost(self):
""" connection lost, same as done writing """
- self._onWriteDone()
+ self._write_progress = 0
+ self._write_size = 1
+ self._update_progress()
def _onWriteDone(self):
""" done writing, zero out progress """
- self._write_progress = 0
- self._write_size = 1
self._update_progress()
+ def complete_extra_step(self, step):
+ self._extra_step_progress += EXTRA_STEP_FRACTION
+
def _update_progress(self):
""" updates the progress bar, capping at 100% """
- self._progress.set_fraction(min(float(self._write_progress) / float(self._write_size),
- 1))
+ new_fraction = min(float(self._write_progress) / float(self._write_size),
+ 1)
+ new_fraction *= (1 - EXTRA_STEP_NUM_STEPS * EXTRA_STEP_FRACTION)
+ new_fraction += self._extra_step_progress
+ self._progress.set_fraction(new_fraction)
def wrap_writeSomeData(self, func):
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]