Useful, robust shell utilities

Jonathan Gardner jgardn at alumni.washington.edu
Fri Mar 1 20:57:08 EST 2002


Donn Cave scribbled with his keyboard:

> Quoth Jonathan Gardner <jgardn at alumni.washington.edu>:
> | I tried to use the shutil module... and to tell you the truth, it
> | stinks. Is there an effort to make a robust, useful shutil module that
> | has the equivalent of the unix shell utilities?
> 
> Go ahead.  Then keep an eye out on comp.lang.python, and after some
> years pass finally someone will mention it:  "it stinks", they'll
> say, with no particular explanation.

=) I didn't mean to be particularly offensive.

It was just that the copytree function has this little comment:

The source code for this should be considered an example rather than a tool.

And it also won't copy to a directory that already exists... this is very 
different than what 'cp' does.

> 
> | I think it would be nice to make things like 'grep' even...
> |
> | Here is my wish list. Each of these should implement a significant
> | portion of what the GNU utils do. They should be robust, and give
> | reasonable results, and reasonable exceptions.
> |
> | touch, chmod, chown, chgrp, touch
> | df, du
> | cp, dd, install, mv, rm, shred
> 
> Some of them are essentially POSIX 1003.1 functions, hence supported in
> the posix module (which we usually call "os" so it will appear that these
> functions are supported on all platforms, whether they really are or not.)
> 
> chmod == chmod()
> chown == chown()
> chgrp == chown()
> rm == unlink()
> mv == rename()
> dd ~= read(), write(), lseek()
> df == fstatvfs()
> 

They do in fact appear in the 'os' module, but they are rather limited to 
the forms of input they take.

For instance, you have to use (octal) numbers for chmod().

There would be a big benefit to see something like:

res = chmod("-c", "-R", "u=rwx,g=rx,o=", a_file, another_file, a_directory)

Even having a function reference you pass in that returns true or false in 
answer to questions like, "Shall I delete this directory?" would be very 
useful.

Well, it looks like I'd better get started. I think 'cp', 'rm' and such 
will be the easiest to implement. Any ideas for a module name?

> Donn Cave, donn at u.washington.edu
Jonathan (jgardn at u.washington.edu)




More information about the Python-list mailing list