Extract all members from the archive to the current working directory and set owner, modification time and permissions on directories afterwards. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by getme
(self, path=".", members=None)
| 448 | |
| 449 | |
| 450 | def _extractall(self, path=".", members=None): |
| 451 | """Extract all members from the archive to the current working |
| 452 | directory and set owner, modification time and permissions on |
| 453 | directories afterwards. `path' specifies a different directory |
| 454 | to extract to. `members' is optional and must be a subset of the |
| 455 | list returned by getmembers(). |
| 456 | """ |
| 457 | import copy |
| 458 | import operator |
| 459 | from tarfile import ExtractError |
| 460 | directories = [] |
| 461 | |
| 462 | if members is None: |
| 463 | members = self |
| 464 | |
| 465 | for tarinfo in members: |
| 466 | if tarinfo.isdir(): |
| 467 | # Extract directories with a safe mode. |
| 468 | directories.append(tarinfo) |
| 469 | tarinfo = copy.copy(tarinfo) |
| 470 | tarinfo.mode = 448 # decimal for oct 0700 |
| 471 | self.extract(tarinfo, path) |
| 472 | |
| 473 | # Reverse sort directories. |
| 474 | if sys.version_info < (2, 4): |
| 475 | def sorter(dir1, dir2): |
| 476 | return cmp(dir1.name, dir2.name) |
| 477 | directories.sort(sorter) |
| 478 | directories.reverse() |
| 479 | else: |
| 480 | directories.sort(key=operator.attrgetter('name'), reverse=True) |
| 481 | |
| 482 | # Set correct owner, mtime and filemode on directories. |
| 483 | for tarinfo in directories: |
| 484 | dirpath = os.path.join(path, tarinfo.name) |
| 485 | try: |
| 486 | self.chown(tarinfo, dirpath) |
| 487 | self.utime(tarinfo, dirpath) |
| 488 | self.chmod(tarinfo, dirpath) |
| 489 | except ExtractError: |
| 490 | e = sys.exc_info()[1] |
| 491 | if self.errorlevel > 1: |
| 492 | raise |
| 493 | else: |
| 494 | self._dbg(1, "tarfile: %s" % e) |
| 495 | |
| 496 | |
| 497 | def _build_install_args(argv): |
no outgoing calls
no test coverage detected