You are not logged in.
Hi there.
So, I had once to copy a bunch of big files from one partition to another.
Just made of few `cp', but I was really feeling like there should have been a progress-bar somewhere ...
I thought that it would be quite easy to write a program that would fork cp as an other process, monitor the size of the source, and the size of the destination, and use this to print a nice progress-bar.
This is how pycp was born, sources were put on gitorious, and a package was made on AUR.
So, feel free to download it and send me any remarks you could have.
Please consider this as an exercise : my own purpose was to learn a bit more about python, AUR, and git
(BTW, setup.py is very nice)
And (who knows ?) ,this script could be useful to you after all
EDIT:
Mandatory screenshot
$~ pycp -g ~/test/tbbt/ /tmp
29% - 45.11 M/s - [######### ] - 2 on 4 ETA : 00:00:11
19% /home/yannick/test/tbbt/t2.avi [##### ] ETA : 00:00:01
Note that sources are now hosted on github:
http://github.com/yannicklm/pycp (gitorious project has been deleted)
Package is available on AUR:
https://aur.archlinux.org/packages/pycp
Last edited by Yannick_LM (2015-09-11 16:46:48)
Offline
it's funny because i had actually thought about writing something like this in the past. I like your version, it seems to work well. The one thing I might suggest is that you should be able to list a directory as the destination and it will keep the same filename, like a regular cp command. Right now this just throws me an error. Ex:
pycp /media/share/Linux/archlinux-2008.06-core-i686.iso /tmp/
Error: '/media/share/Linux/archlinux-2008.06-core-i686.iso' and '/media/share/Linux/archlinux-2008.06-core-i686.iso' are the same file
anyway, just a suggestion! thanks for putting it up!
Offline
¡Cool!
By striving to do the impossible, man has always achieved what is possible. Those who have cautiously done no more than they believed possible have never taken a single step forward - Mikhail Bakunin
Offline
Yup, right now it does not work at all with dirs...
(and I just realised, thanks to your example, that it's not that obvious. Anyway, I'll try to fix this.)
Offline
Could it eventually be a drop-in replacement for cp, so that one can alias cp='pycp' and it will use the same parameters, but will give a progress?
Offline
Could it eventually be a drop-in replacement for cp, so that one can alias cp='pycp' and it will use the same parameters, but will give a progress?
Yup, this is the idea. The keywork is *eventually*
Anyway, I just uploaded a new version, fixing a few bugs.
Offline
well that was fast, thanks! btw, i'm really liking this program. I've always thought cp should optionally have a progressbar
Offline
Not to destroy your enthusiams, but there is a tool in AUR with a similar task: vcp. It works quite well.
Offline
Also, there is another program that does this called bar. It's in [community].
Offline
Not to destroy your enthusiams, but there is a tool in AUR with a similar task: vcp. It works quite well.
Hu, hu
I promiss I made some research before submitting.
(and was expecting something like that to happen)
Thanks for putting that out, guys.
(And vcp is indeed quite nice)
Well, anyway re-inventing the wheel is part of the process isn't it?
Last edited by Yannick_LM (2009-02-15 00:41:29)
Offline
Also, there is a more generalized program for this kind of thing: pv.
For instance, a naive file copy command with progress bar would be:
pcp(){
cat "$1" | pv -s $(ls -s --block-size 1 | cut -d ' ' -f 1) > "$2"
}
Of course, it doesn't deal with globbing and that sort of stuff.
Offline
Good job, very nice and useful script! more straightforward than pv, vcp or bar etc.
If it also has a speed indicator and the elapsed time/total time consumed in copying files, it would be great.
Offline
Version 1.3.1 comes with a file transfer speed and a ETA.
Enjoy!
Last edited by Yannick_LM (2009-02-18 21:31:32)
Offline
Version 1.3.1 comes with a file transfer speed and a ETA.
Enjoy!
woo, thx.
Offline
Version 1.3.1 comes with a file transfer speed and a ETA.
Enjoy!
is it also possible to add a mv feature.
Offline
can you make it work with multiple files?
Done in version 2.1, which is also able to copy directories.
is it also possible to add a mv feature.
That's planned
Offline
some changes in pycp.py to:
support some options
implemented -o|--overwrite option
doesnt overwrite anymore when doing "pycp SOURCE SOURCE DESTINATION_DIRECTORY"
skips existing files instead of canceling whole operation
if knew how to use git, i'd upload it there
EDIT: maybe, to behave more like the real "cp", files should be overwritten by default, unless the -u option is specified, but thatsyour decision
btw: nice little app
64c64
< def __init__(self, source, destination):
---
> def __init__(self, source, destination, cpopts):
68a69
> self.cpopts = cpopts
134c135
< opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "version"])
---
> opts, args = getopt.getopt(sys.argv[1:], "hvo", ["help", "version", "overwrite"])
139a141,142
> cpopts = []
>
146c149
< elif opt == "--version":
---
> elif opt in ("-v", "--version"):
148a152,154
> elif opt in ("-o", "--overwrite"):
> cpopts.append("overwrite")
>
174c180
< recursive_copy(source, destination)
---
> recursive_copy(source, destination, cpopts)
179c185
< def _prepare_copy(source, destination):
---
> def _prepare_copy(source, destination, cpopts):
189a196
> skip = False
199a207,215
>
> source_dir, source_file = path.split(source)
> destination_file = path.join(destination, source_file)
> if ((path.exists(destination_file)) and (not 'overwrite' in cpopts)):
> #print "Error: file '" + destination_file + "' already exists"
> #exit(1)
> print "file '" + destination_file + "' already exists"
> skip = True
>
203,206c219,225
< else:
< # refusing to override an exiting file
< print "Error: file '" + destination + "' already exists"
< exit(1)
---
>
> elif not 'overwrite' in cpopts:
> # refusing to override an exiting file if the -o option is not specified
> #print "Error: file '" + destination + "' already exists"
> #exit(1)
> print "file '" + destination_file + "' already exists"
> skip = True
212c231,232
< exit(1)
---
> #exit(1)
> skip = True
229c249
< return new_destination
---
> return new_destination, skip
233c253
< def recursive_copy(source, destination):
---
> def recursive_copy(source, destination, cpopts):
237c257
< new_destination = _prepare_copy(source, destination)
---
> new_destination, skip = _prepare_copy(source, destination, cpopts)
239,245c259,266
< if path.isdir(source):
< for file_name in listdir(source):
< recursive_copy(path.join(source, file_name),
< path.join(new_destination, file_name))
< else:
< copy_manager = CopyManager(source, new_destination)
< copy_manager.copy()
---
> if (not skip):
> if path.isdir(source):
> for file_name in listdir(source):
> recursive_copy(path.join(source, file_name),
> path.join(new_destination, file_name), cpopts)
> else:
> copy_manager = CopyManager(source, new_destination, cpopts)
> copy_manager.copy()
Last edited by robmaloy (2009-02-24 10:24:08)
☃ Snowman ☃
Offline
Wow, already a patch!
Thanks, I was not expecting so much interest.
EDIT: maybe, to behave more like the real "cp", files should be overwritten by default, unless the -u option is specified, but that's your decision
-u is for --ubuntu I presume ? (1)
</troll>
I'm a huge fan of
" alias cp='cp -i' "
so I'm in favor of keeping the skipping behavior
Having a configuration file just for this looks a bit overkil, but may be fun to implement, so who knows ?
Anyway, version 2.2 comes with robmaloy patch.
(1) EDIT:
I'm also learning about debian (or ubuntu) packaging.
In case someone really bored would like to have a look, it's in a PPA:
https://launchpad.net/~yannick-lm/+archive/ppa
Last edited by Yannick_LM (2009-02-24 22:35:38)
Offline
just so you know, i'm getting a md5 checksum error when upgrading to the latest version (2.2-1)
Offline
Sorry, my mistake.
Fixed in a new package release
pycp-2.2-2
Offline
no worries! keep up the good work!
Offline
Version 3.0 is out!
new: man pages, improved setup.py
add a pymv script.
Right now, it just calls pycp with an argument delete_afterwards
Enjoy!
Offline
Version 3.0 is out!
add a pymv script.
it just calls pycp with an argument delete_afterwards
cool!
but I don't see any changes in git, haven't committed the code?
Last edited by seenxu (2009-03-01 13:31:38)
Offline
but I don't see any changes in git, haven't committed the code?
Just did
Offline