tarinfo.devminor = os.minor(statres.st_rdev)
return tarinfo
- def list(self, verbose=True):
- """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.
+ def list(self, verbose=True, print_func=None):
+ """ Print a table of contents
+
+ If `verbose' is False, only the names of the members are printed. If it
+ is True, an `ls -l'-like output is produced.
+ If print_func is specified, use that instead of print()ing to stdout
"""
self._check()
+ if print_func is None:
+ print_func = print
+
for tarinfo in self:
+ line_parts = []
if verbose:
- print(stat.filemode(tarinfo.mode), end=' ')
- print("%s/%s" % (tarinfo.uname or tarinfo.uid,
- tarinfo.gname or tarinfo.gid), end=' ')
+ line_parts.append(stat.filemode(tarinfo.mode))
+ line_parts.append("%s/%s" % (tarinfo.uname or tarinfo.uid,
+ tarinfo.gname or tarinfo.gid))
if tarinfo.ischr() or tarinfo.isblk():
- print("%10s" % ("%d,%d" \
- % (tarinfo.devmajor, tarinfo.devminor)), end=' ')
+ line_parts.append("%10s" % ("%d,%d" \
+ % (tarinfo.devmajor,
+ tarinfo.devminor)))
else:
- print("%10d" % tarinfo.size, end=' ')
- print("%d-%02d-%02d %02d:%02d:%02d" \
- % time.localtime(tarinfo.mtime)[:6], end=' ')
+ line_parts.append("%10d" % tarinfo.size)
+ line_parts.append("%d-%02d-%02d %02d:%02d:%02d" \
+ % time.localtime(tarinfo.mtime)[:6])
- print(tarinfo.name + ("/" if tarinfo.isdir() else ""), end=' ')
+ line_parts.append(tarinfo.name + ("/" if tarinfo.isdir() else ""))
if verbose:
if tarinfo.issym():
- print("->", tarinfo.linkname, end=' ')
+ line_parts.append("->", tarinfo.linkname)
if tarinfo.islnk():
- print("link to", tarinfo.linkname, end=' ')
- print()
+ line_parts.append("link to", tarinfo.linkname)
+ print_func(' '.join(line_parts))
def add(self, name, arcname=None, recursive=True, exclude=None, *, filter=None):
"""Add the file `name' to the archive. `name' may be any type of file