diff options
| author | jvoisin | 2011-07-30 21:47:31 +0200 |
|---|---|---|
| committer | jvoisin | 2011-07-30 21:47:31 +0200 |
| commit | 5715ba52f2238af513b0b87f4aa3c0158d2c84ba (patch) | |
| tree | e77829efd78b1473650a669546c3c11edc37932c /lib/archive.py | |
| parent | c9cb00bdf702ce6663e78784de63dc6d35c3d875 (diff) | |
Documentation, and removal of unnecessary imports
Diffstat (limited to 'lib/archive.py')
| -rw-r--r-- | lib/archive.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/archive.py b/lib/archive.py index f9e4dba..108134c 100644 --- a/lib/archive.py +++ b/lib/archive.py | |||
| @@ -1,3 +1,6 @@ | |||
| 1 | ''' | ||
| 2 | Take care of archives formats | ||
| 3 | ''' | ||
| 1 | import tarfile | 4 | import tarfile |
| 2 | import zipfile | 5 | import zipfile |
| 3 | 6 | ||
| @@ -67,6 +70,9 @@ class ZipStripper(GenericArchiveStripper): | |||
| 67 | return True | 70 | return True |
| 68 | 71 | ||
| 69 | def is_clean(self): | 72 | def is_clean(self): |
| 73 | ''' | ||
| 74 | Check if the given file is clean from harmful metadata | ||
| 75 | ''' | ||
| 70 | zipin = zipfile.ZipFile(self.filename, 'r') | 76 | zipin = zipfile.ZipFile(self.filename, 'r') |
| 71 | if zipin.comment != '': | 77 | if zipin.comment != '': |
| 72 | logging.debug('%s has a comment' % self.filename) | 78 | logging.debug('%s has a comment' % self.filename) |
| @@ -154,6 +160,9 @@ harmless format' % item.filename) | |||
| 154 | 160 | ||
| 155 | 161 | ||
| 156 | class TarStripper(GenericArchiveStripper): | 162 | class TarStripper(GenericArchiveStripper): |
| 163 | ''' | ||
| 164 | Represent a tarfile archive | ||
| 165 | ''' | ||
| 157 | def _remove(self, current_file): | 166 | def _remove(self, current_file): |
| 158 | ''' | 167 | ''' |
| 159 | remove the meta added by tar itself to the file | 168 | remove the meta added by tar itself to the file |
| @@ -209,6 +218,9 @@ class TarStripper(GenericArchiveStripper): | |||
| 209 | return True | 218 | return True |
| 210 | 219 | ||
| 211 | def is_clean(self): | 220 | def is_clean(self): |
| 221 | ''' | ||
| 222 | Check if the file is clean from harmful metadatas | ||
| 223 | ''' | ||
| 212 | tarin = tarfile.open(self.filename, 'r' + self.compression) | 224 | tarin = tarfile.open(self.filename, 'r' + self.compression) |
| 213 | for item in tarin.getmembers(): | 225 | for item in tarin.getmembers(): |
| 214 | if not self.is_file_clean(item): | 226 | if not self.is_file_clean(item): |
| @@ -233,6 +245,9 @@ class TarStripper(GenericArchiveStripper): | |||
| 233 | return True | 245 | return True |
| 234 | 246 | ||
| 235 | def get_meta(self): | 247 | def get_meta(self): |
| 248 | ''' | ||
| 249 | Return a dict with all the meta of the file | ||
| 250 | ''' | ||
| 236 | tarin = tarfile.open(self.filename, 'r' + self.compression) | 251 | tarin = tarfile.open(self.filename, 'r' + self.compression) |
| 237 | metadata = {} | 252 | metadata = {} |
| 238 | for current_file in tarin.getmembers(): | 253 | for current_file in tarin.getmembers(): |
