Voice et bot modif
This commit is contained in:
parent
189d56026b
commit
7333a22bcd
10774 changed files with 634644 additions and 933308 deletions
|
|
@ -45,7 +45,7 @@ wrapper = SkipRepeatAbsolutePaths().wrap
|
|||
|
||||
@functools.singledispatch
|
||||
@wrapper
|
||||
def mkpath(name: pathlib.Path, mode=0o777, verbose=True, dry_run=False) -> None:
|
||||
def mkpath(name: pathlib.Path, mode=0o777, verbose=True) -> None:
|
||||
"""Create a directory and any missing ancestor directories.
|
||||
|
||||
If the directory already exists (or if 'name' is the empty string, which
|
||||
|
|
@ -58,7 +58,7 @@ def mkpath(name: pathlib.Path, mode=0o777, verbose=True, dry_run=False) -> None:
|
|||
log.info("creating %s", name)
|
||||
|
||||
try:
|
||||
dry_run or name.mkdir(mode=mode, parents=True, exist_ok=True)
|
||||
name.mkdir(mode=mode, parents=True, exist_ok=True)
|
||||
except OSError as exc:
|
||||
raise DistutilsFileError(f"could not create '{name}': {exc.args[-1]}")
|
||||
|
||||
|
|
@ -76,22 +76,22 @@ def _(name: None, *args, **kwargs):
|
|||
raise DistutilsInternalError(f"mkpath: 'name' must be a string (got {name!r})")
|
||||
|
||||
|
||||
def create_tree(base_dir, files, mode=0o777, verbose=True, dry_run=False):
|
||||
def create_tree(base_dir, files, mode=0o777, verbose=True):
|
||||
"""Create all the empty directories under 'base_dir' needed to put 'files'
|
||||
there.
|
||||
|
||||
'base_dir' is just the name of a directory which doesn't necessarily
|
||||
exist yet; 'files' is a list of filenames to be interpreted relative to
|
||||
'base_dir'. 'base_dir' + the directory portion of every file in 'files'
|
||||
will be created if it doesn't already exist. 'mode', 'verbose' and
|
||||
'dry_run' flags are as for 'mkpath()'.
|
||||
will be created if it doesn't already exist. 'mode' and 'verbose'
|
||||
flags are as for 'mkpath()'.
|
||||
"""
|
||||
# First get the list of directories to create
|
||||
need_dir = set(os.path.join(base_dir, os.path.dirname(file)) for file in files)
|
||||
|
||||
# Now create them
|
||||
for dir in sorted(need_dir):
|
||||
mkpath(dir, mode, verbose=verbose, dry_run=dry_run)
|
||||
mkpath(dir, mode, verbose=verbose)
|
||||
|
||||
|
||||
def copy_tree(
|
||||
|
|
@ -102,7 +102,6 @@ def copy_tree(
|
|||
preserve_symlinks=False,
|
||||
update=False,
|
||||
verbose=True,
|
||||
dry_run=False,
|
||||
):
|
||||
"""Copy an entire directory tree 'src' to a new location 'dst'.
|
||||
|
||||
|
|
@ -112,7 +111,7 @@ def copy_tree(
|
|||
file in 'src' is copied to 'dst', and directories under 'src' are
|
||||
recursively copied to 'dst'. Return the list of files that were
|
||||
copied or might have been copied, using their output name. The
|
||||
return value is unaffected by 'update' or 'dry_run': it is simply
|
||||
return value is unaffected by 'update': it is simply
|
||||
the list of all files under 'src', with the names changed to be
|
||||
under 'dst'.
|
||||
|
||||
|
|
@ -123,18 +122,14 @@ def copy_tree(
|
|||
(the default), the destination of the symlink will be copied.
|
||||
'update' and 'verbose' are the same as for 'copy_file'.
|
||||
"""
|
||||
if not dry_run and not os.path.isdir(src):
|
||||
if not os.path.isdir(src):
|
||||
raise DistutilsFileError(f"cannot copy tree '{src}': not a directory")
|
||||
try:
|
||||
names = os.listdir(src)
|
||||
except OSError as e:
|
||||
if dry_run:
|
||||
names = []
|
||||
else:
|
||||
raise DistutilsFileError(f"error listing files in '{src}': {e.strerror}")
|
||||
raise DistutilsFileError(f"error listing files in '{src}': {e.strerror}")
|
||||
|
||||
if not dry_run:
|
||||
mkpath(dst, verbose=verbose)
|
||||
mkpath(dst, verbose=verbose)
|
||||
|
||||
copy_one = functools.partial(
|
||||
_copy_one,
|
||||
|
|
@ -142,7 +137,6 @@ def copy_tree(
|
|||
dst=dst,
|
||||
preserve_symlinks=preserve_symlinks,
|
||||
verbose=verbose,
|
||||
dry_run=dry_run,
|
||||
preserve_mode=preserve_mode,
|
||||
preserve_times=preserve_times,
|
||||
update=update,
|
||||
|
|
@ -157,7 +151,6 @@ def _copy_one(
|
|||
dst,
|
||||
preserve_symlinks,
|
||||
verbose,
|
||||
dry_run,
|
||||
preserve_mode,
|
||||
preserve_times,
|
||||
update,
|
||||
|
|
@ -173,8 +166,7 @@ def _copy_one(
|
|||
link_dest = os.readlink(src_name)
|
||||
if verbose >= 1:
|
||||
log.info("linking %s -> %s", dst_name, link_dest)
|
||||
if not dry_run:
|
||||
os.symlink(link_dest, dst_name)
|
||||
os.symlink(link_dest, dst_name)
|
||||
yield dst_name
|
||||
|
||||
elif os.path.isdir(src_name):
|
||||
|
|
@ -186,7 +178,6 @@ def _copy_one(
|
|||
preserve_symlinks,
|
||||
update,
|
||||
verbose=verbose,
|
||||
dry_run=dry_run,
|
||||
)
|
||||
else:
|
||||
file_util.copy_file(
|
||||
|
|
@ -196,7 +187,6 @@ def _copy_one(
|
|||
preserve_times,
|
||||
update,
|
||||
verbose=verbose,
|
||||
dry_run=dry_run,
|
||||
)
|
||||
yield dst_name
|
||||
|
||||
|
|
@ -212,7 +202,7 @@ def _build_cmdtuple(path, cmdtuples):
|
|||
cmdtuples.append((os.rmdir, path))
|
||||
|
||||
|
||||
def remove_tree(directory, verbose=True, dry_run=False):
|
||||
def remove_tree(directory, verbose=True):
|
||||
"""Recursively remove an entire directory tree.
|
||||
|
||||
Any errors are ignored (apart from being reported to stdout if 'verbose'
|
||||
|
|
@ -220,8 +210,6 @@ def remove_tree(directory, verbose=True, dry_run=False):
|
|||
"""
|
||||
if verbose >= 1:
|
||||
log.info("removing '%s' (and everything under it)", directory)
|
||||
if dry_run:
|
||||
return
|
||||
cmdtuples = []
|
||||
_build_cmdtuple(directory, cmdtuples)
|
||||
for cmd in cmdtuples:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue