Copy recursively the `src` directory to the `dst` directory. If `dst` is an existing directory, files in `dst` may be overwritten during the copy. Preserve timestamps. Ignores: -`src` permissions: `dst` files are created with the default permissions. - all special files su
(src, dst)
| 384 | |
| 385 | |
| 386 | def copytree(src, dst): |
| 387 | """ |
| 388 | Copy recursively the `src` directory to the `dst` directory. If `dst` is an |
| 389 | existing directory, files in `dst` may be overwritten during the copy. |
| 390 | Preserve timestamps. |
| 391 | Ignores: |
| 392 | -`src` permissions: `dst` files are created with the default permissions. |
| 393 | - all special files such as FIFO or character devices and symlinks. |
| 394 | |
| 395 | Raise an shutil.Error with a list of reasons. |
| 396 | |
| 397 | This function is similar to and derived from the Python shutil.copytree |
| 398 | function. See fileutils.py.ABOUT for details. |
| 399 | """ |
| 400 | if not filetype.is_readable(src): |
| 401 | chmod(src, R, recurse=False) |
| 402 | |
| 403 | names = [resource.name for resource in os.scandir(src)] |
| 404 | |
| 405 | if not os.path.exists(dst): |
| 406 | os.makedirs(dst) |
| 407 | |
| 408 | errors = [] |
| 409 | errors.extend(copytime(src, dst)) |
| 410 | |
| 411 | for name in names: |
| 412 | srcname = os.path.join(src, name) |
| 413 | dstname = os.path.join(dst, name) |
| 414 | |
| 415 | # skip anything that is not a regular file, dir or link |
| 416 | if not filetype.is_regular(srcname): |
| 417 | continue |
| 418 | |
| 419 | if not filetype.is_readable(srcname): |
| 420 | chmod(srcname, R, recurse=False) |
| 421 | try: |
| 422 | if os.path.isdir(srcname): |
| 423 | copytree(srcname, dstname) |
| 424 | elif filetype.is_file(srcname): |
| 425 | copyfile(srcname, dstname) |
| 426 | # catch the Error from the recursive copytree so that we can |
| 427 | # continue with other files |
| 428 | except shutil.Error as err: |
| 429 | errors.extend(err.args[0]) |
| 430 | except EnvironmentError as why: |
| 431 | errors.append((srcname, dstname, str(why))) |
| 432 | |
| 433 | if errors: |
| 434 | raise shutil.Error(errors) |
| 435 | |
| 436 | |
| 437 | def copyfile(src, dst): |