Skip to content

Commit

Permalink
track progress for extra upload steps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
David Ignacio authored and deignacio committed Dec 25, 2009
1 parent 36ec246 commit 219b518
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/postr.py
Expand Up @@ -33,7 +33,7 @@
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
Expand Down Expand Up @@ -901,6 +901,7 @@ def add_to_set(self, rsp, set):
"""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):
Expand All @@ -912,13 +913,15 @@ def error(failure):
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):
"""Callback from the upload method to set license for the picture."""
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):
Expand Down Expand Up @@ -1024,16 +1027,23 @@ def upload(self, response=None):

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
Expand Down
26 changes: 21 additions & 5 deletions src/proxyclient.py
Expand Up @@ -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
Expand All @@ -426,11 +434,13 @@ def __init__(self, progress):
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

Expand All @@ -441,18 +451,24 @@ def _onDataWritten(self, size):

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):
"""
Expand Down

0 comments on commit 219b518

Please sign in to comment.