X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fnative_client%2Fbuild%2Ffile_tools.py;h=54f44d1c8bb0594fe7483930e0ca4b7308111886;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=cb9b839cecb7d7e1576b7c3efd950c5157356fbc;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/native_client/build/file_tools.py b/src/native_client/build/file_tools.py index cb9b839..54f44d1 100755 --- a/src/native_client/build/file_tools.py +++ b/src/native_client/build/file_tools.py @@ -118,3 +118,32 @@ def RemoveDirectoryIfPresent(path): if os.path.exists(path): shutil.rmtree(path, onerror=onerror_readonly) + + +def CopyTree(src, dst): + """Recursively copy the items in the src directory to the dst directory. + + Unlike shutil.copytree, the destination directory and any subdirectories and + files may exist. Existing directories are left untouched, and existing files + are removed and copied from the source using shutil.copy2. It is also not + symlink-aware. + + Args: + src: Source. Must be an existing directory. + dst: Destination directory. If it exists, must be a directory. Otherwise it + will be created, along with parent directories. + """ + if not os.path.isdir(dst): + os.makedirs(dst) + for root, dirs, files in os.walk(src): + relroot = os.path.relpath(root, src) + dstroot = os.path.join(dst, relroot) + for d in dirs: + dstdir = os.path.join(dstroot, d) + if not os.path.isdir(dstdir): + os.mkdir(dstdir) + for f in files: + dstfile = os.path.join(dstroot, f) + if os.path.isfile(dstfile): + os.remove(dstfile) + shutil.copy2(os.path.join(root, f), dstfile)