mrsinger at usa.net
Wed Apr 16 16:57:53 CEST 2003
Helps quite a bit... Thanks!
Nicodemus <nicodemus at globalite.com.br> wrote in message news:<mailman.1050460645.26676.python-list at python.org>...
> Matt Singer wrote:
> >I have an application with a PYQT interface that uploads large files.
> >Is there an async method to get how much data has been sent with
> >storlines to update a progress bar? Or is there an alternate ftp
> From the Python docs:
> storlines(command, file)
> Store a file in ASCII transfer mode. command should be an
> appropriate "STOR" command (see storbinary()). Lines are read until EOF
> from the open file object file using its readline() method to provide
> the data to be stored.
> So you can send any object with a readline method that support the same
> semantics of a file (untested code):
> class ProgressFileReader:
> def __init__(self, filename, callback):
> self.file = file(filename, 'r')
> self.file_size = os.path.getsize(filename)
> self.callback = callback # will be called with one parameter:
> # the percentage of the file read so far
> def readline(self, *args):
> result = self.file.readline(*args)
> percent = self.file.tell()*100/self.file_size
> return result
> And use it as follows:
> f = ProgressFileReader('myfile', mycallback)
> ftpobj.storlines('STOR myfile', f)
> Another option would be to subclass the file object.
> Hope that helps,
More information about the Python-list