I'm using this function (based on this awnser) to compress a folder to an encrypted .zip file using 7zip in a subprocess:
def zipbkp(directoryToZip):
zipFileName = directoryToZip+".zip"
password = "minmin3"
appPath = "C:\Program Files\\7-Zip"
zApp = "7z.exe"
zAction = 'a'
zPass = '-p{0} -mhe'.format(password)
zAnswer = '-y'
zDir = directoryToZip
progDir = os.path.join(appPath,zApp)
print("[*] Trying to create .zip File, please wait...")
cmd = [zApp, zAction, zipFileName, zPass, zAnswer, zDir]
zipper = subprocess.Popen(cmd, executable=progDir, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
#Lacking Progressbar here
zipper.wait()
print("[*] Successfully created .zip File")
return zipFileName
This works fine as is. My only problem is since the directory to zip is pretty huge i want to give information about the compression progress.
I've installed and used tqdm succesfully before to display a progressbar but can't get it to work with this 7zip subprocess.
For reference, this is how i used tqdm on a ftp upload script:
with tqdm(unit = 'blocks', unit_scale = True, leave = False, miniters = 1, desc = 'Uploading', total = filesize) as tqdm_instance:
ftp.storbinary('STOR ' + filename, tmp, 2048, callback = lambda sent: tqdm_instance.update(len(sent)))
tqdm even provides an example on how to use pipes but i don't really understand it. The example also is using grep which isn't available on Windows.
I also found this example which is even worse to understand.
Any idea how to get and parse the information provided by 7zip using tqdm?