From 09f43643326a4511850f6a47215f37e6b7f32f51 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 7 Nov 2011 11:32:23 +0100 Subject: Modularity improvement, and clarifications --- mat/mat.py | 46 ++-------------------------------------------- mat/strippers.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 44 deletions(-) create mode 100644 mat/strippers.py 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 import hachoir_core.cmd_line import hachoir_parser -import images -import audio -import office -import archive -import misc +import strippers __version__ = '0.1' __author__ = 'jvoisin' @@ -26,44 +22,6 @@ LOGGING_LEVEL = logging.DEBUG logging.basicConfig(level=LOGGING_LEVEL) -STRIPPERS = { - 'application/x-tar': archive.TarStripper, - 'application/x-gzip': archive.GzipStripper, - 'application/x-bzip2': archive.Bzip2Stripper, - 'application/zip': archive.ZipStripper, - 'audio/mpeg': audio.MpegAudioStripper, - 'application/x-bittorrent': misc.TorrentStripper, - 'application/opendocument': office.OpenDocumentStripper, - 'application/officeopenxml': office.OpenXmlStripper, -} - -try: - import poppler - import cairo - STRIPPERS['application/x-pdf'] = office.PdfStripper - STRIPPERS['application/pdf'] = office.PdfStripper -except ImportError: - print('Unable to import python-poppler and/or python-cairo: no pdf \ - support') - -try: - import mutagen - STRIPPERS['audio/x-flac'] = audio.FlacStripper - STRIPPERS['audio/vorbis'] = audio.OggStripper -except ImportError: - print('Unable to import python-mutagen: limited audio format support') - -try: - # check if exiftool is installed on the system - subprocess.Popen('exiftool', stdout=open('/dev/null')) - import exiftool - STRIPPERS['image/jpeg'] = exiftool.JpegStripper - STRIPPERS['image/png'] = exiftool.PngStripper -except: - print('Unable to find exiftool: limited images support') - STRIPPERS['image/jpeg'] = images.JpegStripper - STRIPPERS['image/png'] = images.PngStripper - def get_sharedir(): ''' @@ -166,7 +124,7 @@ def create_class_file(name, backup, add2archive): mime = 'application/officeopenxml' # office openxml try: - stripper_class = STRIPPERS[mime] + stripper_class = strippers.STRIPPERS[mime] except KeyError: logging.info('Don\'t have stripper for %s format' % mime) 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 @@ +''' + Manage which fileformat can be processed +''' + +import images +import audio +import office +import archive +import misc +import subprocess + +STRIPPERS = { + 'application/x-tar': archive.TarStripper, + 'application/x-gzip': archive.GzipStripper, + 'application/x-bzip2': archive.Bzip2Stripper, + 'application/zip': archive.ZipStripper, + 'audio/mpeg': audio.MpegAudioStripper, + 'application/x-bittorrent': misc.TorrentStripper, + 'application/opendocument': office.OpenDocumentStripper, + 'application/officeopenxml': office.OpenXmlStripper, +} + +try: + import poppler + import cairo + STRIPPERS['application/x-pdf'] = office.PdfStripper + STRIPPERS['application/pdf'] = office.PdfStripper +except ImportError: + print('Unable to import python-poppler and/or python-cairo: no pdf \ + support') + +try: + import mutagen + STRIPPERS['audio/x-flac'] = audio.FlacStripper + STRIPPERS['audio/vorbis'] = audio.OggStripper +except ImportError: + print('Unable to import python-mutagen: limited audio format support') + +try: + # check if exiftool is installed on the system + subprocess.Popen('exiftool', stdout=open('/dev/null')) + import exiftool + STRIPPERS['image/jpeg'] = exiftool.JpegStripper + STRIPPERS['image/png'] = exiftool.PngStripper +except: + print('Unable to find exiftool: limited images support') + STRIPPERS['image/jpeg'] = images.JpegStripper + STRIPPERS['image/png'] = images.PngStripper + -- cgit v1.3