Skip to content

Commit

Permalink
Merge pull request #1097 from danigm/magic-warnings
Browse files Browse the repository at this point in the history
Use python-magic API when available
  • Loading branch information
danigm authored Aug 3, 2023
2 parents fa98be1 + c6ff3e5 commit 389de24
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,25 @@ def parse_deps(line):
return prcos


def _get_magic_libmagic(path):
return magic.detect_from_filename(path).name


def _get_magic_python_magic(path):
return magic.from_file(path)


def get_magic(path):
# python-magic & libmagic compatibility code
# https://github.com/ahupp/python-magic/blob/master/COMPAT.md
detect_magic = _get_magic_python_magic
if not hasattr(magic, 'from_file'):
# libmagic python bindings
detect_magic = _get_magic_libmagic

try:
return magic.detect_from_filename(path).name
except ValueError:
return detect_magic(path)
except (ValueError, FileNotFoundError):
return ''


Expand Down

0 comments on commit 389de24

Please sign in to comment.