473,786 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5739
On Mar 26, 4:41 pm, durumdara <durumd...@gmai l.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=Fals e, callback=None):

"""Open the ZIP file with mode read "r", write "w" or append "a"."""
self._allowZip6 4 = 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(b uf)
compress_size = compress_size + len(buf)
self.fp.write(b uf)

3) Define a callback class and use it:

import zipfile

class CB():
def progress(self, total, sofar):
zippercentcompl ete=100.0*sofar/total
print "callback.progr ess.zippercentc omplete=%.2f" % zippercentcompl ete
return

z=zipfile.ZipFi le(r'C:\testzip .zip', mode='w', callback=CB())
z.write(r'c:\Li brary\TurboDelp hi\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
3941
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
0
1129
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 i = 0; i < 100; i++) { // do stuff
3
4473
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 cmd.exe with ASPNET as a user. But nothing happens. It can't execute the batch file. This is the code i am using to run the batch file:
0
1194
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
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7515
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.