allow no magic

This commit is contained in:
2018-08-21 13:21:15 +03:00
parent 5e662262bc
commit 2c67bc2ca6

View File

@@ -3,7 +3,10 @@ from datetime import datetime
from flask import current_app as app from flask import current_app as app
import requests import requests
import re import re
import magic try:
import magic
except ImportError:
pass
try: try:
from urllib.request import pathname2url from urllib.request import pathname2url
from urllib.request import urlparse from urllib.request import urlparse
@@ -60,7 +63,11 @@ def version_date(full_path):
def file_mime(filename): def file_mime(filename):
return magic.from_file(filename, mime = True) try:
return magic.from_file(filename, mime = True)
except NameError:
# magic not imported
return "NA"
def file_stat(path, filename): def file_stat(path, filename):
full_path = os.path.join(path, filename) full_path = os.path.join(path, filename)