Add get_file_magic to tests/lib.py

Related: rhbz#1673744
This commit is contained in:
Brian C. Lane 2019-02-20 14:14:12 -08:00
parent 1f716641cf
commit d37cf8d0d5

View File

@ -16,6 +16,7 @@
#
import sys
from contextlib import contextmanager
import magic
from io import StringIO
@contextmanager
@ -27,3 +28,17 @@ def captured_output():
yield sys.stdout, sys.stderr
finally:
sys.stdout, sys.stderr = old_out, old_err
def get_file_magic(filename):
"""Get the file type details using libmagic
Returns "" on failure or a string containing the description of the file
"""
details = ""
try:
ms = magic.open(magic.NONE)
ms.load()
details = ms.file(filename)
finally:
ms.close()
return details