2018-05-16 22:00:37 +02:00
|
|
|
#!/bin/env python3
|
|
|
|
|
2018-07-10 20:49:54 +02:00
|
|
|
import os
|
|
|
|
import collections
|
2018-09-06 11:13:11 +02:00
|
|
|
import enum
|
2018-07-10 20:49:54 +02:00
|
|
|
import importlib
|
2018-09-01 15:07:01 +02:00
|
|
|
from typing import Dict, Optional
|
2018-07-10 20:49:54 +02:00
|
|
|
|
|
|
|
# make pyflakes happy
|
|
|
|
assert Dict
|
|
|
|
|
2018-05-16 22:00:37 +02:00
|
|
|
# A set of extension that aren't supported, despite matching a supported mimetype
|
2018-07-08 22:40:36 +02:00
|
|
|
UNSUPPORTED_EXTENSIONS = {
|
2018-06-10 00:28:43 +02:00
|
|
|
'.asc',
|
|
|
|
'.bat',
|
|
|
|
'.brf',
|
|
|
|
'.c',
|
|
|
|
'.h',
|
|
|
|
'.ksh',
|
|
|
|
'.pl',
|
|
|
|
'.pot',
|
|
|
|
'.rdf',
|
|
|
|
'.srt',
|
|
|
|
'.wsdl',
|
|
|
|
'.xpdl',
|
|
|
|
'.xsd',
|
|
|
|
'.xsl',
|
|
|
|
}
|
2018-07-10 20:49:54 +02:00
|
|
|
|
|
|
|
DEPENDENCIES = {
|
|
|
|
'cairo': 'Cairo',
|
|
|
|
'gi': 'PyGobject',
|
|
|
|
'gi.repository.GdkPixbuf': 'GdkPixbuf from PyGobject',
|
|
|
|
'gi.repository.Poppler': 'Poppler from PyGobject',
|
2018-07-15 17:00:01 +02:00
|
|
|
'gi.repository.GLib': 'GLib from PyGobject',
|
2018-07-10 20:49:54 +02:00
|
|
|
'mutagen': 'Mutagen',
|
|
|
|
}
|
|
|
|
|
2018-09-01 16:58:34 +02:00
|
|
|
def _get_exiftool_path() -> Optional[str]: # pragma: no cover
|
2018-09-01 15:07:01 +02:00
|
|
|
exiftool_path = '/usr/bin/exiftool'
|
|
|
|
if os.path.isfile(exiftool_path):
|
2018-09-01 16:58:34 +02:00
|
|
|
if os.access(exiftool_path, os.X_OK):
|
2018-09-01 15:07:01 +02:00
|
|
|
return exiftool_path
|
|
|
|
|
|
|
|
# ArchLinux
|
|
|
|
exiftool_path = '/usr/bin/vendor_perl/exiftool'
|
|
|
|
if os.path.isfile(exiftool_path):
|
2018-09-01 16:58:34 +02:00
|
|
|
if os.access(exiftool_path, os.X_OK):
|
2018-09-01 15:07:01 +02:00
|
|
|
return exiftool_path
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2018-07-10 20:49:54 +02:00
|
|
|
def check_dependencies() -> dict:
|
|
|
|
ret = collections.defaultdict(bool) # type: Dict[str, bool]
|
|
|
|
|
2018-09-01 15:07:01 +02:00
|
|
|
ret['Exiftool'] = True if _get_exiftool_path() else False
|
2018-07-10 20:49:54 +02:00
|
|
|
|
|
|
|
for key, value in DEPENDENCIES.items():
|
|
|
|
ret[value] = True
|
|
|
|
try:
|
|
|
|
importlib.import_module(key)
|
|
|
|
except ImportError: # pragma: no cover
|
|
|
|
ret[value] = False # pragma: no cover
|
|
|
|
|
|
|
|
return ret
|
2018-09-06 00:49:35 +02:00
|
|
|
|
2018-09-06 11:13:11 +02:00
|
|
|
@enum.unique
|
|
|
|
class UnknownMemberPolicy(enum.Enum):
|
2018-09-06 00:49:35 +02:00
|
|
|
ABORT = 'abort'
|
|
|
|
OMIT = 'omit'
|
|
|
|
KEEP = 'keep'
|