aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-07-07 14:31:42 +0300
committerFrederick Muriuki Muriithi2022-07-07 14:31:42 +0300
commitd939d999903bb59388bf504760a4ae5407213520 (patch)
tree4850c664fbb638cec000c60409c2c133c6e9aa79
parentfdec747a0a33a96aefb3cc8d2e8717f13bea6c20 (diff)
downloadgn-uploader-d939d999903bb59388bf504760a4ae5407213520.tar.gz
Replace 'magic' with builtin 'mimetypes'
Use the builtin mimetypes which gives better results
-rw-r--r--scripts/qc.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/scripts/qc.py b/scripts/qc.py
index de01bb7..2057cd6 100644
--- a/scripts/qc.py
+++ b/scripts/qc.py
@@ -2,10 +2,9 @@
import os
import sys
import argparse
+import mimetypes
from typing import Union, Callable
-import magic
-
from quality_control.utils import make_progress_calculator
from quality_control.errors import InvalidValue, DuplicateHeading
from quality_control.parsing import (
@@ -15,9 +14,10 @@ from quality_control.parsing import (
collect_errors)
-def is_file_mime(filepath, mimetype):
+def is_file_mime(filepath:str, mimetype:str) -> bool:
"""Check that `filepath` has a mimetype of `mimetype` or `text/plain`"""
- return magic.from_file(filepath, mime=True) in ("text/plain", mimetype)
+ the_type = mimetypes.guess_type(filepath)[0]
+ return the_type in ("text/plain", mimetype)
def cli_argument_parser():
"""Create the parser for the CLI arguments"""