473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Zip file writing progress (callback proc)

Hi!

I want to check my zip file writings.
I need some callback procedure to show a progress bar.
Can I do that?
I don't want to modify the PyLib module to extend it, because if I get
another py, the changes are lost.
This happening too if I copy the zip module to modify it.
Any solution?

Thanks for it:
dd
Mar 26 '07 #1
2 5638
On Mar 26, 4:41 pm, durumdara <durumd...@gmail.comwrote:
Hi!

I want to check my zip file writings.
I need some callback procedure to show a progress bar.
Can I do that?
I don't want to modify the PyLib module to extend it, because if I get
another py, the changes are lost.
This happening too if I copy the zip module to modify it.
Any solution?

Thanks for it:
dd
Would it be enough to show progress based on how many files have
been added to the zip? If you're zipping just one huge file, I'm
afraid you can't get a progress bar using the zipfile module.

If it's not necessary that the one file is a zip but simply
compressed,
you can use zlib or bz2 modules to compress incrementally:
http://www.python.org/doc/lib/node303.html
Mar 26 '07 #2
durumdara wrote:
Hi!

I want to check my zip file writings.
I need some callback procedure to show a progress bar.
Can I do that?
I don't want to modify the PyLib module to extend it, because if I get
another py, the changes are lost.
This happening too if I copy the zip module to modify it.
Any solution?

Thanks for it:
dd
I did this by extending the write method of my zipfile module.

1) Add a callback= keyword argument to __init__ and saving that in
an instance variable (self._callback).

def __init__(self, file, mode="r", compression=ZIP_STORED,
allowZip64=False, callback=None):

"""Open the ZIP file with mode read "r", write "w" or append "a"."""
self._allowZip64 = allowZip64
self._didModify = False
self._callback = callback # new instance variable to be used in write


2) Change write method so that it calls the progress method of the callback
function after every block is written (if user passed in one).

while 1:
buf = fp.read(1024 * 8)
if not buf:
break
file_size = file_size + len(buf)
#-----New lines follow
#
# Call the progress method of the callback function (if defined)
#
if self._callback is not None:
self._callback.progress(st.st_size, fp.tell())

#-----End of new lines
CRC = binascii.crc32(buf, CRC)
if cmpr:
buf = cmpr.compress(buf)
compress_size = compress_size + len(buf)
self.fp.write(buf)

3) Define a callback class and use it:

import zipfile

class CB():
def progress(self, total, sofar):
zippercentcomplete=100.0*sofar/total
print "callback.progress.zippercentcomplete=%.2f" % zippercentcomplete
return

z=zipfile.ZipFile(r'C:\testzip.zip', mode='w', callback=CB())
z.write(r'c:\Library\TurboDelphi\TurboDelphi.exe')

At least by doing it this way you won't break anything if you get a new zipfile
module. It just won't show progress any more and then you can patch it.

Hope info helps.

-Larry Bates
Mar 27 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: Adam Byrne | last post by:
Been wondering about this... Which is better? (pseudocode - please don't grill me about semantics etc.) public class Thing { public void DoLongOperation(IProgressCallback callback) { for (int...
3
by: emman_54 | last post by:
Hi every one, I am trying to run a batch file using my asp.net application. I am using the Process class to run the batch file. When I run my web application, In the task manager, i could see...
0
by: alex21 | last post by:
I want to display the progress of the WebClient.DownloadString() method using a progress bar? Anyone know? Thanks Alex.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.