def do(): if not os.path.exists(downloads_dir): os.makedirs(downloads_dir) u = urllib2.urlopen(url) filepath = os.path.join(downloads_dir, filename) f = open(filepath, 'wb') meta = u.info() filesize = int(meta.getheaders("Content-Length")[0]) complete = 0 while True: block = u.read(32*1024) if not block: break complete += len(block) f.write(block) update_task("%.1f%%" % (float(complete*100)/filesize)) f.close()
def update_task(id, data, username=''): task_obj = task.update_task(id, data, username) serializer = TaskBriefSerializer(task_obj) return serializer.data