RKrahl / archive-tools

Tools for managing archives
Apache License 2.0
1 stars 2 forks source link

archive-tool.py fails with NameError when tying to emit a warning #46

Closed RKrahl closed 3 years ago

RKrahl commented 3 years ago

A warning is raised when trying to add a file to an archive having an unsupported type, ref. #34:

>>> from pathlib import Path
>>> from archive.archive import Archive
>>> archive = Archive().create(Path("archive-tmp.tar"), "", [Path("/tmp/.X11-unix")])
/usr/lib/python3.6/site-packages/archive/manifest.py:135: ArchiveWarning: /tmp/.X11-unix/X0: socket ignored
  warnings.warn(ArchiveWarning("%s ignored" % e))

But the command line script archive-tool.py fails with a NameError while trying to emit this warning:

$ archive-tool create archive-tmp.tar /tmp/.X11-unix
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/archive/manifest.py", line 133, in iterpaths
    info = cls(path=p)
  File "/usr/lib/python3.6/site-packages/archive/manifest.py", line 61, in __init__
    raise ArchiveInvalidTypeError(self.path, ftype)
archive.exception.ArchiveInvalidTypeError: /tmp/.X11-unix/X0: socket

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/archive-tool", line 5, in <module>
    archive.cli.archive_tool()
  File "/usr/lib/python3.6/site-packages/archive/cli/__init__.py", line 44, in archive_tool
    sys.exit(args.func(args))
  File "/usr/lib/python3.6/site-packages/archive/cli/create.py", line 28, in create
    tags=args.tag)
  File "/usr/lib/python3.6/site-packages/archive/archive.py", line 76, in create
    self._create(path, mode, paths, basedir, excludes, dedup, tags)
  File "/usr/lib/python3.6/site-packages/archive/archive.py", line 82, in _create
    self.manifest = Manifest(paths=paths, excludes=excludes, tags=tags)
  File "/usr/lib/python3.6/site-packages/archive/manifest.py", line 165, in __init__
    self.fileinfos = sorted(fileinfos, key=lambda fi: fi.path)
  File "/usr/lib/python3.6/site-packages/archive/manifest.py", line 140, in iterpaths
    yield from cls.iterpaths(p.iterdir(), excludes)
  File "/usr/lib/python3.6/site-packages/archive/manifest.py", line 135, in iterpaths
    warnings.warn(ArchiveWarning("%s ignored" % e))
  File "/usr/lib64/python3.6/warnings.py", line 99, in _showwarnmsg
    msg.file, msg.line)
  File "/usr/lib/python3.6/site-packages/archive/cli/__init__.py", line 25, in showwarning
    s = "%s: %s\n" % (argparser.prog, message)
NameError: name 'argparser' is not defined
RKrahl commented 3 years ago

This is a regression that has been introduced in 935f277. The bug thus affects versions 0.4 and 0.5.