File: __init__.py

package info (click to toggle)
mat2 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,376 kB
  • sloc: python: 3,772; makefile: 7
file content (96 lines) | stat: -rw-r--r-- 1,976 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3

import enum
import importlib
from typing import Dict

from . import exiftool, video

# A set of extension that aren't supported, despite matching a supported mimetype
UNSUPPORTED_EXTENSIONS = {
    '.asc',
    '.bat',
    '.brf',
    '.c',
    '.h',
    '.ksh',
    '.pl',
    '.pot',
    '.rdf',
    '.srt',
    '.wsdl',
    '.xpdl',
    '.xsd',
    '.xsl',
    }

DEPENDENCIES = {
    'Cairo': {
        'module': 'cairo',
        'required': True,
    },
    'PyGobject': {
        'module': 'gi',
        'required': True,
    },
    'GdkPixbuf from PyGobject': {
        'module': 'gi.repository.GdkPixbuf',
        'required': True,
    },
    'Poppler from PyGobject': {
        'module': 'gi.repository.Poppler',
        'required': True,
    },
    'GLib from PyGobject': {
        'module': 'gi.repository.GLib',
        'required': True,
    },
    'Mutagen': {
        'module': 'mutagen',
        'required': True,
    },
}

CMD_DEPENDENCIES = {
    'Exiftool': {
        'cmd': exiftool._get_exiftool_path,
        'required': False,
    },
    'Ffmpeg': {
        'cmd': video._get_ffmpeg_path,
        'required': False,
    },
}


def check_dependencies() -> Dict[str, Dict[str, bool]]:
    ret: Dict[str, Dict] = dict()

    for key, value in DEPENDENCIES.items():
        ret[key] = {
            'found': True,
            'required': value['required'],
        }
        try:
            importlib.import_module(value['module'])  # type: ignore
        except ImportError:  # pragma: no cover
            ret[key]['found'] = False

    for k, v in CMD_DEPENDENCIES.items():
        ret[k] = {
            'found': True,
            'required': v['required'],
        }
        try:
            v['cmd']()  # type: ignore
        except RuntimeError:  # pragma: no cover
            ret[k]['found'] = False

    return ret


@enum.unique
class UnknownMemberPolicy(enum.Enum):
    ABORT = 'abort'
    OMIT = 'omit'
    KEEP = 'keep'