diff options
| author | jvoisin | 2011-07-24 02:30:50 +0200 |
|---|---|---|
| committer | jvoisin | 2011-07-24 02:30:50 +0200 |
| commit | ace3d8213921a9308d30afc057fc21221420e12e (patch) | |
| tree | be506ef8b0534127ad080f7d1ad7d4ca9a020a67 /lib/mat.py | |
| parent | bcc0ad2e7491c212ef35ca250fb8c5f2c53572da (diff) | |
First implementation of open document format
Diffstat (limited to 'lib/mat.py')
| -rw-r--r-- | lib/mat.py | 36 |
1 files changed, 28 insertions, 8 deletions
| @@ -7,6 +7,7 @@ | |||
| 7 | import os | 7 | import os |
| 8 | import subprocess | 8 | import subprocess |
| 9 | import logging | 9 | import logging |
| 10 | import mimetypes | ||
| 10 | 11 | ||
| 11 | import hachoir_core.cmd_line | 12 | import hachoir_core.cmd_line |
| 12 | import hachoir_parser | 13 | import hachoir_parser |
| @@ -14,7 +15,7 @@ import hachoir_editor | |||
| 14 | 15 | ||
| 15 | import images | 16 | import images |
| 16 | import audio | 17 | import audio |
| 17 | import misc | 18 | import office |
| 18 | import archive | 19 | import archive |
| 19 | 20 | ||
| 20 | __version__ = "0.1" | 21 | __version__ = "0.1" |
| @@ -29,7 +30,7 @@ strippers = { | |||
| 29 | hachoir_parser.image.PngFile: images.PngStripper, | 30 | hachoir_parser.image.PngFile: images.PngStripper, |
| 30 | hachoir_parser.image.bmp.BmpFile: images.BmpStripper, | 31 | hachoir_parser.image.bmp.BmpFile: images.BmpStripper, |
| 31 | hachoir_parser.audio.MpegAudioFile: audio.MpegAudioStripper, | 32 | hachoir_parser.audio.MpegAudioFile: audio.MpegAudioStripper, |
| 32 | hachoir_parser.misc.PDFDocument: misc.PdfStripper, | 33 | hachoir_parser.misc.PDFDocument: office.PdfStripper, |
| 33 | hachoir_parser.archive.TarFile: archive.TarStripper, | 34 | hachoir_parser.archive.TarFile: archive.TarStripper, |
| 34 | hachoir_parser.archive.gzip_parser.GzipParser: archive.GzipStripper, | 35 | hachoir_parser.archive.gzip_parser.GzipParser: archive.GzipStripper, |
| 35 | hachoir_parser.archive.bzip2_parser.Bzip2Parser: archive.Bzip2Stripper, | 36 | hachoir_parser.archive.bzip2_parser.Bzip2Parser: archive.Bzip2Stripper, |
| @@ -61,12 +62,14 @@ def create_class_file(name, backup, add2archive): | |||
| 61 | corresponding to the filetype of the given file | 62 | corresponding to the filetype of the given file |
| 62 | ''' | 63 | ''' |
| 63 | if is_secure(name): | 64 | if is_secure(name): |
| 64 | print 'a' | ||
| 65 | return | 65 | return |
| 66 | 66 | ||
| 67 | filename = "" | 67 | filename = "" |
| 68 | realname = name | 68 | realname = name |
| 69 | filename = hachoir_core.cmd_line.unicodeFilename(name) | 69 | try: |
| 70 | filename = hachoir_core.cmd_line.unicodeFilename(name) | ||
| 71 | except TypeError:# get rid of "TypeError: decoding Unicode is not supported" | ||
| 72 | filename = name | ||
| 70 | parser = hachoir_parser.createParser(filename) | 73 | parser = hachoir_parser.createParser(filename) |
| 71 | if not parser: | 74 | if not parser: |
| 72 | logging.error("Unable to parse %s" % filename) | 75 | logging.error("Unable to parse %s" % filename) |
| @@ -82,9 +85,26 @@ def create_class_file(name, backup, add2archive): | |||
| 82 | stripper_class = strippers[editor.input.__class__] | 85 | stripper_class = strippers[editor.input.__class__] |
| 83 | except KeyError: | 86 | except KeyError: |
| 84 | #Place for another lib than hachoir | 87 | #Place for another lib than hachoir |
| 85 | logging.error("Don't have stripper for file type %s" % editor.description) | 88 | logging.error("Don't have stripper for format %s" % editor.description) |
| 86 | return | 89 | return |
| 87 | if editor.input.__class__ == hachoir_parser.misc.PDFDocument: | 90 | |
| 91 | if editor.input.__class__ == hachoir_parser.misc.PDFDocument:#pdf | ||
| 88 | return stripper_class(filename, realname, backup) | 92 | return stripper_class(filename, realname, backup) |
| 89 | return stripper_class(realname, filename, parser, editor, backup, | 93 | |
| 90 | add2archive) | 94 | elif editor.input.__class__ == hachoir_parser.archive.zip.ZipFile: |
| 95 | #zip based format | ||
| 96 | mime = mimetypes.guess_type(filename)[0] | ||
| 97 | try:#Ugly workaround, cleaning open document delete mime (wtf?) | ||
| 98 | if mime.startswith(#Open document format | ||
| 99 | 'application/vnd.oasis.opendocument'): | ||
| 100 | return office.OpenDocumentStripper(realname, filename, parser, | ||
| 101 | editor, backup, add2archive) | ||
| 102 | else:#normal zip | ||
| 103 | return stripper_class(realname, filename, parser, editor, | ||
| 104 | backup, add2archive) | ||
| 105 | except:#normal zip file | ||
| 106 | return stripper_class(realname, filename, parser, editor, backup, | ||
| 107 | add2archive) | ||
| 108 | else:#normal handling | ||
| 109 | return stripper_class(realname, filename, parser, editor, backup, | ||
| 110 | add2archive) | ||
