diff options
| author | jvoisin | 2011-07-25 03:21:40 +0200 |
|---|---|---|
| committer | jvoisin | 2011-07-25 03:21:40 +0200 |
| commit | ea21231d6d332b5e27e85c0ce0c103cfb56433f8 (patch) | |
| tree | ec1ca1681f44d19a53599af1980a358e751594e0 /lib | |
| parent | 7bec354973580216c64889b925e1f7d6a224d7dd (diff) | |
Correct handling of unknown fileformat into zipfile (and fixe many previous-commit-bugs)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/archive.py | 6 | ||||
| -rw-r--r-- | lib/office.py | 4 | ||||
| -rw-r--r-- | lib/parser.py | 4 |
3 files changed, 8 insertions, 6 deletions
diff --git a/lib/archive.py b/lib/archive.py index 21bc5c5..6e3efc0 100644 --- a/lib/archive.py +++ b/lib/archive.py | |||
| @@ -59,9 +59,11 @@ class ZipStripper(GenericArchiveStripper): | |||
| 59 | cfile = mat.create_class_file(name, False, | 59 | cfile = mat.create_class_file(name, False, |
| 60 | self.add2archive) | 60 | self.add2archive) |
| 61 | except: | 61 | except: |
| 62 | #best solution I have found | ||
| 62 | logging.error('%s is not supported' % item.filename) | 63 | logging.error('%s is not supported' % item.filename) |
| 63 | #Returning false is the best solution imho | 64 | _, ext = os.path.splitext(name) |
| 64 | return False | 65 | if ext not in parser.NOMETA: |
| 66 | return False | ||
| 65 | mat.secure_remove(name) | 67 | mat.secure_remove(name) |
| 66 | zipin.close() | 68 | zipin.close() |
| 67 | return False | 69 | return False |
diff --git a/lib/office.py b/lib/office.py index 2302dbc..9a5be3e 100644 --- a/lib/office.py +++ b/lib/office.py | |||
| @@ -27,7 +27,7 @@ class OpenDocumentStripper(archive.GenericArchiveStripper): | |||
| 27 | method here : http://bugs.python.org/issue6818 | 27 | method here : http://bugs.python.org/issue6818 |
| 28 | ''' | 28 | ''' |
| 29 | zipin = zipfile.ZipFile(self.filename, 'r') | 29 | zipin = zipfile.ZipFile(self.filename, 'r') |
| 30 | zipout = zipfile.ZipFile(self.basename + parser.POSTFIX + self.ext, 'w', | 30 | zipout = zipfile.ZipFile(self.output, 'w', |
| 31 | allowZip64=True) | 31 | allowZip64=True) |
| 32 | for item in zipin.namelist(): | 32 | for item in zipin.namelist(): |
| 33 | name = os.path.join(self.tempdir, item) | 33 | name = os.path.join(self.tempdir, item) |
| @@ -134,7 +134,7 @@ class PdfStripper(parser.Generic_parser): | |||
| 134 | ''' | 134 | ''' |
| 135 | def __init__(self, filename, realname, backup): | 135 | def __init__(self, filename, realname, backup): |
| 136 | name, path = os.path.splitext(filename) | 136 | name, path = os.path.splitext(filename) |
| 137 | self.output = name + '.cleaned.' + ext | 137 | self.output = name + '.cleaned' + ext |
| 138 | self.filename = filename | 138 | self.filename = filename |
| 139 | self.backup = backup | 139 | self.backup = backup |
| 140 | self.realname = realname | 140 | self.realname = realname |
diff --git a/lib/parser.py b/lib/parser.py index 11e776e..04d7625 100644 --- a/lib/parser.py +++ b/lib/parser.py | |||
| @@ -13,12 +13,12 @@ import mimetypes | |||
| 13 | 13 | ||
| 14 | import mat | 14 | import mat |
| 15 | 15 | ||
| 16 | NOMETA = ('*.txt', '*.bmp', '*.py') | 16 | NOMETA = ('.txt', '.bmp', '.py', '.xml') |
| 17 | 17 | ||
| 18 | class Generic_parser(object): | 18 | class Generic_parser(object): |
| 19 | def __init__(self, realname, filename, parser, editor, backup, add2archive): | 19 | def __init__(self, realname, filename, parser, editor, backup, add2archive): |
| 20 | basename, ext = os.path.splitext(filename) | 20 | basename, ext = os.path.splitext(filename) |
| 21 | self.output = basename + '.cleaned.' + ext | 21 | self.output = basename + '.cleaned' + ext |
| 22 | self.filename = filename #path + filename | 22 | self.filename = filename #path + filename |
| 23 | self.realname = realname #path + filename | 23 | self.realname = realname #path + filename |
| 24 | self.shortname = os.path.basename(filename) #only filename | 24 | self.shortname = os.path.basename(filename) #only filename |
