Skip to content Skip to sidebar Skip to footer

Python Openstack SDK Show File Upload Via Progress Bar

With the python openstack SDK, you can download an image, chunk by chunk, which allowed me to show a progress bar. You can't seem to do the same when uploading a file. What I want

Solution 1:

So, after quite a bit of searching I was able to find a way to do what I was asking (here & here).

code:

#!/usr/bin/env python3
from types import MethodType

def hook(hookfunk, oldfunc):
    def merged(self, *args, **kwargs):
        hookfunk(self, *args, **kwargs)
        return oldfunc(*args, **kwargs)
    return  MethodType(merged, oldfunc.__self__)


f = open('cirros.qcow2', 'rb')

def new_read(self, size):
    print(self)
    # Or do other code, like updating a progress bar

f.read = hook(new_read, f.read)

f.read()

Post a Comment for "Python Openstack SDK Show File Upload Via Progress Bar"