Python Forum

Full Version: Progress Finished Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Hi all. First post, very new to Python and programming in general. K, now the question:
I have this script:
import sys, shutil, subprocess, ffmpy

def getDimensions(inputVideo):
    args = '-v error -select_streams v:0 -show_entries stream=width,height ' \
           '-of compact'
    call = ffmpy.FFprobe(r'E:\\App Back-Ups\FFprobe\ffprobe.exe', args, \
                         {inputVideo : None})
    return call.run(None, subprocess.PIPE)

def getHeight(tupleIn):
    a = str(tupleIn[0])
    b = a.rfind('=')
    return a[b + 1:b + 4]

toMove = sys.argv[1]
output = getDimensions(toMove)
height = getHeight(output)
if height == '480':
    pathStr1 = 'E:\\My Movies\DVD Rips\\'
    pathStr2 = 'G:\\My Movies\DVD Rips'
else:
    pathStr1 = 'E:\\My Movies\Blu-ray Rips\\'
    pathStr2 = 'G:\\My Movies\Blu-ray Rips'

lastSep = toMove.rfind('\\')
toCopy = pathStr1 + toMove[lastSep + 1:]
shutil.move(toMove, pathStr1)
shutil.copy(toCopy, pathStr2)
input('Press \'Enter\' to exit...')
sys.exit()
It works fine, but sometimes the movie file sizes are quite large and they take a while to copy. I'm wondering how to add a progress bar or percent (preferable) to the runtime. I'm stuck figuring out how because shutil pauses while it's processing the move/copy and does not pick up the next line of script until after it has finished the copy. So, is it possible to add a simple percentage copied output to this script? Just so I know how much is done and how much more is left.
Think about what you're asking. How can you know % done if you have no communication from the program that is using the time?
I guess you can't? I know that shutil has no function that returns progress complete. I was thinking I could compare the size of the file with how much has been copied/moved as it happens. But, the script pauses at the copy/move functions until the file operation is done.
Well, you can run shutil.copy/move in a separate thread and compare the file size against the destination file and do some math to get the percentage or some other measure. You can use this and pass it to the tqdm module for example.
Sweet! Thanks, @wavic. I'm about as noob as they come so know nothing about threads, but Google and the official docs do. I'll look into this further.
Consider that it will takes some time to check the size of copied file and compare it during to copying process. So the value will have a small difference.
So, it won't be terribly accurate? Average file size is about 6GB.
It will be fine.
Great. I must confess, threading makes my brain hurt. It's a lot for a greenhorn noob. Oh well. Thanks again, @wavic.
I am not very familiar with threading because I didn't use it.
The simplest approach:

import thread

source = '/path/big_file.BIG'
dest_path = '/path'
thread.start_new_thread(shutil.copy, (source, dest_path))
You provide the callable and the arguments to the start_new_thread method and that's all.
But this won't tell you if the copping is finished.

Better see this. It's basically almost the same. On top
Pages: 1 2 3 4