471,338 Members | 993 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

shutil & verbose feedback

46
hey guys

any ideas on how to get shutil.copytree to give feedback with what it is copying? (verbose style?)

i can't seem to google up anything on it

cheers if you can help!

Adam
Jun 16 '07 #1
4 3797
bartonc
6,596 Expert 4TB
hey guys

any ideas on how to get shutil.copytree to give feedback with what it is copying? (verbose style?)

i can't seem to google up anything on it

cheers if you can help!

Adam
Hey Adam. I have an idea... Take the docs at their word and "XXX Consider this example code rather than the ultimate tool". Start with source and start adding to it to make your own verbose copytree():
Expand|Select|Wrap|Line Numbers
  1.  
  2. def copytree(src, dst, symlinks=False):
  3.     """Recursively copy a directory tree using copy2().
  4.  
  5.     The destination directory must not already exist.
  6.     If exception(s) occur, an Error is raised with a list of reasons.
  7.  
  8.     If the optional symlinks flag is true, symbolic links in the
  9.     source tree result in symbolic links in the destination tree; if
  10.     it is false, the contents of the files pointed to by symbolic
  11.     links are copied.
  12.  
  13.     XXX Consider this example code rather than the ultimate tool.
  14.  
  15.     """
  16.     names = os.listdir(src)
  17.     os.mkdir(dst)
  18.     errors = []
  19.     for name in names:
  20.         srcname = os.path.join(src, name)
  21.         dstname = os.path.join(dst, name)
  22.         try:
  23.             if symlinks and os.path.islink(srcname):
  24.                 linkto = os.readlink(srcname)
  25.                 os.symlink(linkto, dstname)
  26.             elif os.path.isdir(srcname):
  27.                 copytree(srcname, dstname, symlinks)
  28.             else:
  29.                 copy2(srcname, dstname)
  30.             # XXX What about devices, sockets etc.?
  31.         except (IOError, os.error), why:
  32.             errors.append((srcname, dstname, why))
  33.         # catch the Error from the recursive copytree so that we can
  34.         # continue with other files
  35.         except Error, err:
  36.             errors.extend(err.args[0])
  37.     if errors:
  38.         raise Error, errors
Jun 16 '07 #2
ateale
46
cheers bartonc! didn't know you could do that!
Jun 16 '07 #3
bartonc
6,596 Expert 4TB
cheers bartonc! didn't know you could do that!
In fact it's encouraged! With modules that provide object interfaces, we subclass.
With modules that have functionality that needs adding to, do it. Then, when you post here, it goes out into the public and python grows! That's really the way that a lot of the current library was built (albeit, in a slightly more controlled environment).

And you can call me Barton.

Cheers, Adam.
Jun 16 '07 #4
ateale
46
Cheers Barton!

Ahhh so much to learn!

I am really enjoying learning the language so far. It seems to be starting to make some sense

Cheers for your help!

Adam
Jun 16 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Daniel Bickett | last post: by
1 post views Thread by Todd7 | last post: by
6 posts views Thread by Antoine De Groote | last post: by
8 posts views Thread by David Nicolson | last post: by
4 posts views Thread by Roopesh | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.