Print a table of contents to sys.stdout. If 'verbose' is False, only the names of the members are printed. If it is True, an 'ls -l'-like output is produced. 'members' is optional and must be a subset of the list returned by getmembers().
(self, verbose=True, *, members=None)
| 2265 | return tarinfo |
| 2266 | |
| 2267 | def list(self, verbose=True, *, members=None): |
| 2268 | """Print a table of contents to sys.stdout. If 'verbose' is False, only |
| 2269 | the names of the members are printed. If it is True, an 'ls -l'-like |
| 2270 | output is produced. 'members' is optional and must be a subset of the |
| 2271 | list returned by getmembers(). |
| 2272 | """ |
| 2273 | # Convert tarinfo type to stat type. |
| 2274 | type2mode = {REGTYPE: stat.S_IFREG, SYMTYPE: stat.S_IFLNK, |
| 2275 | FIFOTYPE: stat.S_IFIFO, CHRTYPE: stat.S_IFCHR, |
| 2276 | DIRTYPE: stat.S_IFDIR, BLKTYPE: stat.S_IFBLK} |
| 2277 | self._check() |
| 2278 | |
| 2279 | if members is None: |
| 2280 | members = self |
| 2281 | for tarinfo in members: |
| 2282 | if verbose: |
| 2283 | if tarinfo.mode is None: |
| 2284 | _safe_print("??????????") |
| 2285 | else: |
| 2286 | modetype = type2mode.get(tarinfo.type, 0) |
| 2287 | _safe_print(stat.filemode(modetype | tarinfo.mode)) |
| 2288 | _safe_print("%s/%s" % (tarinfo.uname or tarinfo.uid, |
| 2289 | tarinfo.gname or tarinfo.gid)) |
| 2290 | if tarinfo.ischr() or tarinfo.isblk(): |
| 2291 | _safe_print("%10s" % |
| 2292 | ("%d,%d" % (tarinfo.devmajor, tarinfo.devminor))) |
| 2293 | else: |
| 2294 | _safe_print("%10d" % tarinfo.size) |
| 2295 | if tarinfo.mtime is None: |
| 2296 | _safe_print("????-??-?? ??:??:??") |
| 2297 | else: |
| 2298 | _safe_print("%d-%02d-%02d %02d:%02d:%02d" \ |
| 2299 | % time.localtime(tarinfo.mtime)[:6]) |
| 2300 | |
| 2301 | _safe_print(tarinfo.name + ("/" if tarinfo.isdir() else "")) |
| 2302 | |
| 2303 | if verbose: |
| 2304 | if tarinfo.issym(): |
| 2305 | _safe_print("-> " + tarinfo.linkname) |
| 2306 | if tarinfo.islnk(): |
| 2307 | _safe_print("link to " + tarinfo.linkname) |
| 2308 | print() |
| 2309 | |
| 2310 | def add(self, name, arcname=None, recursive=True, *, filter=None): |
| 2311 | """Add the file 'name' to the archive. 'name' may be any type of file |