This is a code snippet. A screenshot would give you a better idea:
When we do a file copy with high-level function, we would not have option to display current status normally. I have thought of two ways to resolve this: a) copying chuck by chuck by our own code, or b) using threading.
I wrote a Python script, FileCopyProgress.py (Apache License 2.0), to demonstrate them. Before you try this script, you need a test.bin to test. You can use a command like:
head -c 128m /dev/urandom > test.bin
1 Chuck by Chuck: CopyChuck()
This is easy to understand. Simply open two files, input and output files, read from source for a chuck of data, then write to the output file. Flush out after one writing, and get filesize of output file.
2 Copy in Thread: CopyInThread()
This is not a hard one, either. I chose to make copying in a thread, you can make the progress reporting in a thread, or both are in threads. Moreover, if there are many files need to copy, you can have many copying threads at the same time. Don’t try that on same disk, it’s useless and meaningless, or you can queue those copying requests on same disk.
Note that this script is not a complete program and I have only tested on my Fedora 9.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.