Skip to content

Commit

Permalink
progress_bar
Browse files Browse the repository at this point in the history
  • Loading branch information
unhammer committed Dec 10, 2012
1 parent a9cf401 commit 2ab57d5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pressfolder.py
Expand Up @@ -15,6 +15,23 @@
raise e


class Progress(object):
def __init__(self, name):
self._seen = 0.0
self._last_pct = 0.0
self._name = name

def update(self, total, size):
self._seen += size
pct = (self._seen / total) * 100.0

if pct > self._last_pct:
print '%s %.2f %% done' % (self._name, pct)
self._last_pct = pct
# If size is very small and total is big, pct
# stays the same, so don't update


def getBlog(wp_url, wp_user, wp_pass, blogid):
print "Connecting to " + wp_url
wp = wordpresslib.WordPressClient(xmlrpc_url(wp_url),
Expand All @@ -39,7 +56,7 @@ def upload_cwd(blog):
for i in images:
print "Uploading " + i + " ..."

url = blog.newMediaObject(i)
url = blog.newMediaObject(i, Progress(i).update)

html += "<p><img src=\"%s\" alt=\"%s\" class=\"pressfolder\"/></p>\n" % (
url, os.path.basename(i)
Expand Down

0 comments on commit 2ab57d5

Please sign in to comment.