diff options
Diffstat (limited to 'lib/archive.py')
| -rw-r--r-- | lib/archive.py | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/lib/archive.py b/lib/archive.py index f11506a..1aaf74b 100644 --- a/lib/archive.py +++ b/lib/archive.py | |||
| @@ -10,7 +10,7 @@ import parser | |||
| 10 | import mat | 10 | import mat |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | class GenericArchiveStripper(parser.Generic_parser): | 13 | class GenericArchiveStripper(parser.GenericParser): |
| 14 | ''' | 14 | ''' |
| 15 | Represent a generic archive | 15 | Represent a generic archive |
| 16 | ''' | 16 | ''' |
| @@ -29,24 +29,40 @@ class GenericArchiveStripper(parser.Generic_parser): | |||
| 29 | shutil.rmtree(self.tempdir) | 29 | shutil.rmtree(self.tempdir) |
| 30 | 30 | ||
| 31 | def remove_all(self): | 31 | def remove_all(self): |
| 32 | ''' | ||
| 33 | Call _remove_all() with in argument : "normal" | ||
| 34 | ''' | ||
| 32 | self._remove_all('normal') | 35 | self._remove_all('normal') |
| 33 | 36 | ||
| 34 | def remove_all_ugly(self): | 37 | def remove_all_ugly(self): |
| 38 | ''' | ||
| 39 | call remove_all() with in argument : "ugly" | ||
| 40 | ''' | ||
| 35 | self._remove_all('ugly') | 41 | self._remove_all('ugly') |
| 36 | 42 | ||
| 43 | def _remove_all(self, method): | ||
| 44 | ''' | ||
| 45 | Remove all meta, normal way if method is "normal", | ||
| 46 | else, use the ugly way (with possible data loss) | ||
| 47 | ''' | ||
| 48 | raise NotImplementedError | ||
| 37 | 49 | ||
| 38 | class ZipStripper(GenericArchiveStripper): | 50 | class ZipStripper(GenericArchiveStripper): |
| 39 | ''' | 51 | ''' |
| 40 | Represent a zip file | 52 | Represent a zip file |
| 41 | ''' | 53 | ''' |
| 42 | def is_file_clean(self, file): | 54 | def is_file_clean(self, fileinfo): |
| 43 | if file.comment is not '': | 55 | ''' |
| 56 | Check if a ZipInfo object is clean of metadatas added | ||
| 57 | by zip itself, independently of the corresponding file metadatas | ||
| 58 | ''' | ||
| 59 | if fileinfo.comment is not '': | ||
| 44 | return False | 60 | return False |
| 45 | elif file.date_time is not 0: | 61 | elif fileinfo.date_time is not 0: |
| 46 | return False | 62 | return False |
| 47 | elif file.create_system is not 0: | 63 | elif fileinfo.create_system is not 0: |
| 48 | return False | 64 | return False |
| 49 | elif file.create_version is not 0: | 65 | elif fileinfo.create_version is not 0: |
| 50 | return False | 66 | return False |
| 51 | else: | 67 | else: |
| 52 | return True | 68 | return True |
| @@ -74,7 +90,7 @@ class ZipStripper(GenericArchiveStripper): | |||
| 74 | #best solution I have found | 90 | #best solution I have found |
| 75 | logging.info('%s\'s fileformat is not supported, or is a \ | 91 | logging.info('%s\'s fileformat is not supported, or is a \ |
| 76 | harmless format' % item.filename) | 92 | harmless format' % item.filename) |
| 77 | base, ext = os.path.splitext(name) | 93 | _, ext = os.path.splitext(name) |
| 78 | bname = os.path.basename(item.filename) | 94 | bname = os.path.basename(item.filename) |
| 79 | if ext not in parser.NOMETA: | 95 | if ext not in parser.NOMETA: |
| 80 | if bname != 'mimetype': | 96 | if bname != 'mimetype': |
| @@ -84,6 +100,10 @@ harmless format' % item.filename) | |||
| 84 | return True | 100 | return True |
| 85 | 101 | ||
| 86 | def get_meta(self): | 102 | def get_meta(self): |
| 103 | ''' | ||
| 104 | Return all the metadata of a ZipFile (don't return metadatas | ||
| 105 | of contained files : should it ?) | ||
| 106 | ''' | ||
| 87 | zipin = zipfile.ZipFile(self.filename, 'r') | 107 | zipin = zipfile.ZipFile(self.filename, 'r') |
| 88 | metadata = {} | 108 | metadata = {} |
| 89 | for field in zipin.infolist(): | 109 | for field in zipin.infolist(): |
| @@ -231,6 +251,9 @@ class TarStripper(GenericArchiveStripper): | |||
| 231 | 251 | ||
| 232 | 252 | ||
| 233 | class GzipStripper(TarStripper): | 253 | class GzipStripper(TarStripper): |
| 254 | ''' | ||
| 255 | Represent a tar.gz archive | ||
| 256 | ''' | ||
| 234 | def __init__(self, realname, filename, parser, editor, backup, | 257 | def __init__(self, realname, filename, parser, editor, backup, |
| 235 | add2archive): | 258 | add2archive): |
| 236 | super(GzipStripper, self).__init__(realname, | 259 | super(GzipStripper, self).__init__(realname, |
| @@ -239,6 +262,9 @@ class GzipStripper(TarStripper): | |||
| 239 | 262 | ||
| 240 | 263 | ||
| 241 | class Bzip2Stripper(TarStripper): | 264 | class Bzip2Stripper(TarStripper): |
| 265 | ''' | ||
| 266 | Represents a tar.bz2 archive | ||
| 267 | ''' | ||
| 242 | def __init__(self, realname, filename, parser, editor, backup, | 268 | def __init__(self, realname, filename, parser, editor, backup, |
| 243 | add2archive): | 269 | add2archive): |
| 244 | super(Bzip2Stripper, self).__init__(realname, | 270 | super(Bzip2Stripper, self).__init__(realname, |
