Wiki
Clone wikicopymon / Home
Copymon - CP with progressbar
Table of content:
Introduction to Copymon
Copymon is a monitoring facility for copy operations. The python code provides a wrapper to various copy programs such as cp, rsync and tar and provides means to display a progress bar during the copy operation.
This projects provides both a python script named copymon.py which can be used as a replacement for cp and several Python classes which can be used perform the copy operation from within a python code. Using the python classes you can replace the progress bar implementation and add additional copy programs.
How does Copymon works
Copymon works in two stages:
- The source directory is scanned and mapped into a data structure (dict) allowing the rest of the code to determine how much of the copy was done.
- The actual copy program (cp,rsync,..) is spawned in a verbose mode. This means the copy program output one line for each file copied. This output of the copy program is monitored and for each file copied the internal status of the copy is updated. Once in a while (user parameter) the progressbar class is updated.
If errors were detected during the copy process, the program collects all of them and presents them at the end of the copy operation.
copymon.py usage examples
Using cp to copy, displaying a grayscale progress bar
Using cp to copy, displaying a color progress bar
Color progress bar with errors detectd during copy
copymon.py
#!bash galoren@ilanmiz:~/Desktop/copymon/bin$ ./copymon.py --help usage: copymon.py [-h] [--only-scan] [--cp] [--rsync] [--tar] [-p TYPE] [--flags] [--verbose] [--error] source-dir destination-dir copymon monitor a copy operation and presents a progress bar Usages: Copy using cp: ./copymon.py --cp ~/src/d1/ ~/src/d2/ Copy using rsync: ./copymon.py --rsync ~/src/d1/ ~/src/d2/ Copy with Colors: ./copymon.py -p color-terminal --cp ~/src/d1/ ~/src/d2/ positional arguments: source-dir Source directory destination-dir Destination directory optional arguments: -h, --help show this help message and exit --only-scan, -s Perform only scan, omit copy stage --cp Copy directory using cp --rsync Copy directory using rsync --tar Copy directory using tar -p TYPE, --progress TYPE Progress bar type (terminal, color-terminal) --flags Flags for the copy command --verbose Verbose --error Error Authors: Lior Amar, Gal Oren
Copymon Python Code Explained
Copymon several modules: Metadata scanning:
- MetadataScanner - provides recursive scanning of a directory and holding a data structure for all the metadata found.
Monitoring copy operation:
- ICopyMonitor - provides the base class for the copy monitoring operation. This class provides all the implementation of spawning the copy program and monitoring its output.
- CpMonitor - implements the necessary details for using cp. For example, parsing cp output line and determining if the cp was done successfuly or with error.
- RsyncMonitor - implements the necessary details for using rsync as a copy program in the same host.
- TarMonitor - implements the necessary details for using tar as a copy program .
Progressbar handling:
- IProgressBar - provides the interface to be used by progress bars.
- TerminalProgressBar - provides a terminal oriented one line progress bar (no color).
- ColorTerminalProgressBar - a terminal one line progress bar with color.
Updated