~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-07 17:21:55 UTC
  • mto: (1908.2.1 commit-perf)
  • mto: This revision was merged to the branch mainline in revision 1923.
  • Revision ID: john@arbash-meinel.com-20060807172155-62ec9d7e15e34adb
create a copy_tree wrapper around walkdirs()

Show diffs side-by-side

added added

removed removed

Lines of Context:
927
927
                pending.append(dir)
928
928
 
929
929
 
 
930
def copy_tree(from_path, to_path):
 
931
    """Copy all of the entries in from_path into to_path.
 
932
 
 
933
    :param from_path: The base directory to copy. 
 
934
    :param to_path: The target directory. If it does not exist, it will
 
935
        be created.
 
936
    """
 
937
    # Now, just copy the existing cached tree to the new location
 
938
    # We use a cheap trick here.
 
939
    # Absolute paths are prefixed with the first parameter
 
940
    # relative paths are prefixed with the second.
 
941
    # So we can get both the source and target returned
 
942
    # without any extra work.
 
943
 
 
944
    if not os.path.exists(to_path):
 
945
        os.mkdir(to_path)
 
946
 
 
947
    for dir_info, entries in walkdirs(from_path, prefix=to_path):
 
948
        for relpath, name, kind, st, abspath in entries:
 
949
            if kind == 'directory':
 
950
                os.mkdir(relpath)
 
951
            elif kind == 'symlink':
 
952
                link_to = os.readlink(abspath)
 
953
                os.symlink(link_to, relpath)
 
954
            else:
 
955
                assert kind == 'file'
 
956
                shutil.copy(abspath, relpath)
 
957
 
 
958
 
930
959
def path_prefix_key(path):
931
960
    """Generate a prefix-order path key for path.
932
961