summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mat/mat.py46
-rw-r--r--mat/strippers.py49
2 files changed, 51 insertions, 44 deletions
diff --git a/mat/mat.py b/mat/mat.py
index 248777e..0e66df8 100644
--- a/mat/mat.py
+++ b/mat/mat.py
@@ -13,11 +13,7 @@ import xml.sax
13import hachoir_core.cmd_line 13import hachoir_core.cmd_line
14import hachoir_parser 14import hachoir_parser
15 15
16import images 16import strippers
17import audio
18import office
19import archive
20import misc
21 17
22__version__ = '0.1' 18__version__ = '0.1'
23__author__ = 'jvoisin' 19__author__ = 'jvoisin'
@@ -26,44 +22,6 @@ LOGGING_LEVEL = logging.DEBUG
26 22
27logging.basicConfig(level=LOGGING_LEVEL) 23logging.basicConfig(level=LOGGING_LEVEL)
28 24
29STRIPPERS = {
30 'application/x-tar': archive.TarStripper,
31 'application/x-gzip': archive.GzipStripper,
32 'application/x-bzip2': archive.Bzip2Stripper,
33 'application/zip': archive.ZipStripper,
34 'audio/mpeg': audio.MpegAudioStripper,
35 'application/x-bittorrent': misc.TorrentStripper,
36 'application/opendocument': office.OpenDocumentStripper,
37 'application/officeopenxml': office.OpenXmlStripper,
38}
39
40try:
41 import poppler
42 import cairo
43 STRIPPERS['application/x-pdf'] = office.PdfStripper
44 STRIPPERS['application/pdf'] = office.PdfStripper
45except ImportError:
46 print('Unable to import python-poppler and/or python-cairo: no pdf \
47 support')
48
49try:
50 import mutagen
51 STRIPPERS['audio/x-flac'] = audio.FlacStripper
52 STRIPPERS['audio/vorbis'] = audio.OggStripper
53except ImportError:
54 print('Unable to import python-mutagen: limited audio format support')
55
56try:
57 # check if exiftool is installed on the system
58 subprocess.Popen('exiftool', stdout=open('/dev/null'))
59 import exiftool
60 STRIPPERS['image/jpeg'] = exiftool.JpegStripper
61 STRIPPERS['image/png'] = exiftool.PngStripper
62except:
63 print('Unable to find exiftool: limited images support')
64 STRIPPERS['image/jpeg'] = images.JpegStripper
65 STRIPPERS['image/png'] = images.PngStripper
66
67 25
68def get_sharedir(): 26def get_sharedir():
69 ''' 27 '''
@@ -166,7 +124,7 @@ def create_class_file(name, backup, add2archive):
166 mime = 'application/officeopenxml' # office openxml 124 mime = 'application/officeopenxml' # office openxml
167 125
168 try: 126 try:
169 stripper_class = STRIPPERS[mime] 127 stripper_class = strippers.STRIPPERS[mime]
170 except KeyError: 128 except KeyError:
171 logging.info('Don\'t have stripper for %s format' % mime) 129 logging.info('Don\'t have stripper for %s format' % mime)
172 return 130 return
diff --git a/mat/strippers.py b/mat/strippers.py
new file mode 100644
index 0000000..7e5ac9e
--- /dev/null
+++ b/mat/strippers.py
@@ -0,0 +1,49 @@
1'''
2 Manage which fileformat can be processed
3'''
4
5import images
6import audio
7import office
8import archive
9import misc
10import subprocess
11
12STRIPPERS = {
13 'application/x-tar': archive.TarStripper,
14 'application/x-gzip': archive.GzipStripper,
15 'application/x-bzip2': archive.Bzip2Stripper,
16 'application/zip': archive.ZipStripper,
17 'audio/mpeg': audio.MpegAudioStripper,
18 'application/x-bittorrent': misc.TorrentStripper,
19 'application/opendocument': office.OpenDocumentStripper,
20 'application/officeopenxml': office.OpenXmlStripper,
21}
22
23try:
24 import poppler
25 import cairo
26 STRIPPERS['application/x-pdf'] = office.PdfStripper
27 STRIPPERS['application/pdf'] = office.PdfStripper
28except ImportError:
29 print('Unable to import python-poppler and/or python-cairo: no pdf \
30 support')
31
32try:
33 import mutagen
34 STRIPPERS['audio/x-flac'] = audio.FlacStripper
35 STRIPPERS['audio/vorbis'] = audio.OggStripper
36except ImportError:
37 print('Unable to import python-mutagen: limited audio format support')
38
39try:
40 # check if exiftool is installed on the system
41 subprocess.Popen('exiftool', stdout=open('/dev/null'))
42 import exiftool
43 STRIPPERS['image/jpeg'] = exiftool.JpegStripper
44 STRIPPERS['image/png'] = exiftool.PngStripper
45except:
46 print('Unable to find exiftool: limited images support')
47 STRIPPERS['image/jpeg'] = images.JpegStripper
48 STRIPPERS['image/png'] = images.PngStripper
49