diff options
| author | jvoisin | 2011-11-07 11:32:23 +0100 |
|---|---|---|
| committer | jvoisin | 2011-11-07 11:32:23 +0100 |
| commit | 09f43643326a4511850f6a47215f37e6b7f32f51 (patch) | |
| tree | d75269fcc41a3a951bc547f6c605d7a1bff80816 | |
| parent | abb7a0154e593f6b2263c0a641b6b0d104cbc2a4 (diff) | |
Modularity improvement, and clarifications
| -rw-r--r-- | mat/mat.py | 46 | ||||
| -rw-r--r-- | mat/strippers.py | 49 |
2 files changed, 51 insertions, 44 deletions
| @@ -13,11 +13,7 @@ import xml.sax | |||
| 13 | import hachoir_core.cmd_line | 13 | import hachoir_core.cmd_line |
| 14 | import hachoir_parser | 14 | import hachoir_parser |
| 15 | 15 | ||
| 16 | import images | 16 | import strippers |
| 17 | import audio | ||
| 18 | import office | ||
| 19 | import archive | ||
| 20 | import 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 | ||
| 27 | logging.basicConfig(level=LOGGING_LEVEL) | 23 | logging.basicConfig(level=LOGGING_LEVEL) |
| 28 | 24 | ||
| 29 | STRIPPERS = { | ||
| 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 | |||
| 40 | try: | ||
| 41 | import poppler | ||
| 42 | import cairo | ||
| 43 | STRIPPERS['application/x-pdf'] = office.PdfStripper | ||
| 44 | STRIPPERS['application/pdf'] = office.PdfStripper | ||
| 45 | except ImportError: | ||
| 46 | print('Unable to import python-poppler and/or python-cairo: no pdf \ | ||
| 47 | support') | ||
| 48 | |||
| 49 | try: | ||
| 50 | import mutagen | ||
| 51 | STRIPPERS['audio/x-flac'] = audio.FlacStripper | ||
| 52 | STRIPPERS['audio/vorbis'] = audio.OggStripper | ||
| 53 | except ImportError: | ||
| 54 | print('Unable to import python-mutagen: limited audio format support') | ||
| 55 | |||
| 56 | try: | ||
| 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 | ||
| 62 | except: | ||
| 63 | print('Unable to find exiftool: limited images support') | ||
| 64 | STRIPPERS['image/jpeg'] = images.JpegStripper | ||
| 65 | STRIPPERS['image/png'] = images.PngStripper | ||
| 66 | |||
| 67 | 25 | ||
| 68 | def get_sharedir(): | 26 | def 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 | |||
| 5 | import images | ||
| 6 | import audio | ||
| 7 | import office | ||
| 8 | import archive | ||
| 9 | import misc | ||
| 10 | import subprocess | ||
| 11 | |||
| 12 | STRIPPERS = { | ||
| 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 | |||
| 23 | try: | ||
| 24 | import poppler | ||
| 25 | import cairo | ||
| 26 | STRIPPERS['application/x-pdf'] = office.PdfStripper | ||
| 27 | STRIPPERS['application/pdf'] = office.PdfStripper | ||
| 28 | except ImportError: | ||
| 29 | print('Unable to import python-poppler and/or python-cairo: no pdf \ | ||
| 30 | support') | ||
| 31 | |||
| 32 | try: | ||
| 33 | import mutagen | ||
| 34 | STRIPPERS['audio/x-flac'] = audio.FlacStripper | ||
| 35 | STRIPPERS['audio/vorbis'] = audio.OggStripper | ||
| 36 | except ImportError: | ||
| 37 | print('Unable to import python-mutagen: limited audio format support') | ||
| 38 | |||
| 39 | try: | ||
| 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 | ||
| 45 | except: | ||
| 46 | print('Unable to find exiftool: limited images support') | ||
| 47 | STRIPPERS['image/jpeg'] = images.JpegStripper | ||
| 48 | STRIPPERS['image/png'] = images.PngStripper | ||
| 49 | |||
