Recursively remove an entire directory tree. Any errors are ignored (apart from being reported to stdout if 'verbose' is true).
(directory, verbose=1, dry_run=0)
| 176 | cmdtuples.append((os.rmdir, path)) |
| 177 | |
| 178 | def remove_tree(directory, verbose=1, dry_run=0): |
| 179 | """Recursively remove an entire directory tree. |
| 180 | |
| 181 | Any errors are ignored (apart from being reported to stdout if 'verbose' |
| 182 | is true). |
| 183 | """ |
| 184 | global _path_created |
| 185 | |
| 186 | if verbose >= 1: |
| 187 | log.info("removing '%s' (and everything under it)", directory) |
| 188 | if dry_run: |
| 189 | return |
| 190 | cmdtuples = [] |
| 191 | _build_cmdtuple(directory, cmdtuples) |
| 192 | for cmd in cmdtuples: |
| 193 | try: |
| 194 | cmd[0](cmd[1]) |
| 195 | # remove dir from cache if it's already there |
| 196 | abspath = os.path.abspath(cmd[1]) |
| 197 | if abspath in _path_created: |
| 198 | del _path_created[abspath] |
| 199 | except OSError as exc: |
| 200 | log.warn("error removing %s: %s", directory, exc) |
| 201 | |
| 202 | def ensure_relative(path): |
| 203 | """Take the full path 'path', and make it a relative path. |