shutil & verbose feedback

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ateale
    New Member
    • Jun 2007
    • 46

    #1

    shutil & verbose feedback

    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
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by ateale
    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():[CODE=python]

    def copytree(src, dst, symlinks=False) :
    """Recursiv ely copy a directory tree using copy2().

    The destination directory must not already exist.
    If exception(s) occur, an Error is raised with a list of reasons.

    If the optional symlinks flag is true, symbolic links in the
    source tree result in symbolic links in the destination tree; if
    it is false, the contents of the files pointed to by symbolic
    links are copied.

    XXX Consider this example code rather than the ultimate tool.

    """
    names = os.listdir(src)
    os.mkdir(dst)
    errors = []
    for name in names:
    srcname = os.path.join(sr c, name)
    dstname = os.path.join(ds t, name)
    try:
    if symlinks and os.path.islink( srcname):
    linkto = os.readlink(src name)
    os.symlink(link to, dstname)
    elif os.path.isdir(s rcname):
    copytree(srcnam e, dstname, symlinks)
    else:
    copy2(srcname, dstname)
    # XXX What about devices, sockets etc.?
    except (IOError, os.error), why:
    errors.append(( srcname, dstname, why))
    # catch the Error from the recursive copytree so that we can
    # continue with other files
    except Error, err:
    errors.extend(e rr.args[0])
    if errors:
    raise Error, errors[/CODE]

    Comment

    • ateale
      New Member
      • Jun 2007
      • 46

      #3
      cheers bartonc! didn't know you could do that!

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by ateale
        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.

        Comment

        • ateale
          New Member
          • Jun 2007
          • 46

          #5
          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

          Comment

          Working...