diff options
| author | jvoisin | 2015-11-25 19:29:18 +0100 |
|---|---|---|
| committer | jvoisin | 2015-11-26 15:47:30 +0100 |
| commit | 2212039d70ce5c4e97c3943bb82d4231c10e1260 (patch) | |
| tree | afd2aedcf6bb4c2a9fc82d6f3b2d0f7ad2d0fbb8 /libmat/archive.py | |
| parent | 9ea3c2cbc456bfa9a903eaa0ed6a42a34d12e1c2 (diff) | |
Make the logging more pep-282 compliant
See https://www.python.org/dev/peps/pep-0282/ for details,
but basically this is commit leaves the string
replacement to the logging function, instead of
doing it in place in its parameters with the '%' operator.
Diffstat (limited to 'libmat/archive.py')
| -rw-r--r-- | libmat/archive.py | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/libmat/archive.py b/libmat/archive.py index 703ee66..ca80161 100644 --- a/libmat/archive.py +++ b/libmat/archive.py | |||
| @@ -87,25 +87,23 @@ class ZipStripper(GenericArchiveStripper): | |||
| 87 | ret_list = [] | 87 | ret_list = [] |
| 88 | zipin = zipfile.ZipFile(self.filename, 'r') | 88 | zipin = zipfile.ZipFile(self.filename, 'r') |
| 89 | if zipin.comment != '' and not list_unsupported: | 89 | if zipin.comment != '' and not list_unsupported: |
| 90 | logging.debug('%s has a comment' % self.filename) | 90 | logging.debug('%s has a comment', self.filename) |
| 91 | return False | 91 | return False |
| 92 | for item in zipin.infolist(): | 92 | for item in zipin.infolist(): |
| 93 | zipin.extract(item, self.tempdir) | 93 | zipin.extract(item, self.tempdir) |
| 94 | path = os.path.join(self.tempdir, item.filename) | 94 | path = os.path.join(self.tempdir, item.filename) |
| 95 | if not self.__is_zipfile_clean(item) and not list_unsupported: | 95 | if not self.__is_zipfile_clean(item) and not list_unsupported: |
| 96 | logging.debug('%s from %s has compromising zipinfo' % | 96 | logging.debug('%s from %s has compromising zipinfo', item.filename, self.filename) |
| 97 | (item.filename, self.filename)) | ||
| 98 | return False | 97 | return False |
| 99 | if os.path.isfile(path): | 98 | if os.path.isfile(path): |
| 100 | cfile = mat.create_class_file(path, False, add2archive=self.add2archive) | 99 | cfile = mat.create_class_file(path, False, add2archive=self.add2archive) |
| 101 | if cfile is not None: | 100 | if cfile is not None: |
| 102 | if not cfile.is_clean(): | 101 | if not cfile.is_clean(): |
| 103 | logging.debug('%s from %s has metadata' % (item.filename, self.filename)) | 102 | logging.debug('%s from %s has metadata', item.filename, self.filename) |
| 104 | if not list_unsupported: | 103 | if not list_unsupported: |
| 105 | return False | 104 | return False |
| 106 | else: | 105 | else: |
| 107 | logging.info('%s\'s fileformat is not supported or harmless.' | 106 | logging.info('%s\'s fileformat is not supported or harmless.', item.filename) |
| 108 | % item.filename) | ||
| 109 | basename, ext = os.path.splitext(path) | 107 | basename, ext = os.path.splitext(path) |
| 110 | if os.path.basename(item.filename) not in ('mimetype', '.rels'): | 108 | if os.path.basename(item.filename) not in ('mimetype', '.rels'): |
| 111 | if ext not in parser.NOMETA: | 109 | if ext not in parser.NOMETA: |
| @@ -136,8 +134,7 @@ class ZipStripper(GenericArchiveStripper): | |||
| 136 | if cfile_meta != {}: | 134 | if cfile_meta != {}: |
| 137 | metadata[item.filename] = str(cfile_meta) | 135 | metadata[item.filename] = str(cfile_meta) |
| 138 | else: | 136 | else: |
| 139 | logging.info('%s\'s fileformat is not supported or harmless' | 137 | logging.info('%s\'s fileformat is not supported or harmless', item.filename) |
| 140 | % item.filename) | ||
| 141 | zipin.close() | 138 | zipin.close() |
| 142 | return metadata | 139 | return metadata |
| 143 | 140 | ||
| @@ -188,9 +185,9 @@ class ZipStripper(GenericArchiveStripper): | |||
| 188 | os.chmod(path, old_stat | stat.S_IWUSR) | 185 | os.chmod(path, old_stat | stat.S_IWUSR) |
| 189 | cfile.remove_all() | 186 | cfile.remove_all() |
| 190 | os.chmod(path, old_stat) | 187 | os.chmod(path, old_stat) |
| 191 | logging.debug('Processing %s from %s' % (item.filename, self.filename)) | 188 | logging.debug('Processing %s from %s', item.filename, self.filename) |
| 192 | elif item.filename not in whitelist: | 189 | elif item.filename not in whitelist: |
| 193 | logging.info('%s\'s format is not supported or harmless' % item.filename) | 190 | logging.info("%s's format is not supported or harmless", item.filename) |
| 194 | basename, ext = os.path.splitext(path) | 191 | basename, ext = os.path.splitext(path) |
| 195 | if not (self.add2archive or ext in parser.NOMETA): | 192 | if not (self.add2archive or ext in parser.NOMETA): |
| 196 | continue | 193 | continue |
| @@ -205,7 +202,7 @@ class ZipStripper(GenericArchiveStripper): | |||
| 205 | zipin.close() | 202 | zipin.close() |
| 206 | zipout.close() | 203 | zipout.close() |
| 207 | 204 | ||
| 208 | logging.info('%s processed' % self.filename) | 205 | logging.info('%s processed', self.filename) |
| 209 | self.do_backup() | 206 | self.do_backup() |
| 210 | return True | 207 | return True |
| 211 | 208 | ||
| @@ -248,12 +245,11 @@ class TarStripper(GenericArchiveStripper): | |||
| 248 | cfile.remove_all() | 245 | cfile.remove_all() |
| 249 | os.chmod(path, old_stat) | 246 | os.chmod(path, old_stat) |
| 250 | elif self.add2archive or os.path.splitext(item.name)[1] in parser.NOMETA: | 247 | elif self.add2archive or os.path.splitext(item.name)[1] in parser.NOMETA: |
| 251 | logging.debug('%s\' format is either not supported or harmless' % item.name) | 248 | logging.debug("%s' format is either not supported or harmless", item.name) |
| 252 | elif item.name in whitelist: | 249 | elif item.name in whitelist: |
| 253 | logging.debug('%s is not supported, but MAT was told to add it anyway.' | 250 | logging.debug('%s is not supported, but MAT was told to add it anyway.', item.name) |
| 254 | % item.name) | ||
| 255 | else: # Don't add the file to the archive | 251 | else: # Don't add the file to the archive |
| 256 | logging.debug('%s will not be added' % item.name) | 252 | logging.debug('%s will not be added', item.name) |
| 257 | continue | 253 | continue |
| 258 | tarout.add(unicode(path.decode('utf-8')), | 254 | tarout.add(unicode(path.decode('utf-8')), |
| 259 | unicode(item.name.decode('utf-8')), | 255 | unicode(item.name.decode('utf-8')), |
| @@ -291,8 +287,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 291 | tarin = tarfile.open(self.filename, 'r' + self.compression) | 287 | tarin = tarfile.open(self.filename, 'r' + self.compression) |
| 292 | for item in tarin.getmembers(): | 288 | for item in tarin.getmembers(): |
| 293 | if not self.is_file_clean(item) and not list_unsupported: | 289 | if not self.is_file_clean(item) and not list_unsupported: |
| 294 | logging.debug('%s from %s has compromising tarinfo' % | 290 | logging.debug('%s from %s has compromising tarinfo', item.name, self.filename) |
| 295 | (item.name, self.filename)) | ||
| 296 | return False | 291 | return False |
| 297 | tarin.extract(item, self.tempdir) | 292 | tarin.extract(item, self.tempdir) |
| 298 | path = os.path.join(self.tempdir, item.name) | 293 | path = os.path.join(self.tempdir, item.name) |
| @@ -300,15 +295,14 @@ class TarStripper(GenericArchiveStripper): | |||
| 300 | cfile = mat.create_class_file(path, False, add2archive=self.add2archive) | 295 | cfile = mat.create_class_file(path, False, add2archive=self.add2archive) |
| 301 | if cfile is not None: | 296 | if cfile is not None: |
| 302 | if not cfile.is_clean(): | 297 | if not cfile.is_clean(): |
| 303 | logging.debug('%s from %s has metadata' % | 298 | logging.debug('%s from %s has metadata', item.name.decode("utf8"), self.filename) |
| 304 | (item.name.decode("utf8"), self.filename)) | ||
| 305 | if not list_unsupported: | 299 | if not list_unsupported: |
| 306 | return False | 300 | return False |
| 307 | # Nested archives are treated like unsupported files | 301 | # Nested archives are treated like unsupported files |
| 308 | elif isinstance(cfile, GenericArchiveStripper): | 302 | elif isinstance(cfile, GenericArchiveStripper): |
| 309 | ret_list.append(item.name) | 303 | ret_list.append(item.name) |
| 310 | else: | 304 | else: |
| 311 | logging.error('%s\'s format is not supported or harmless' % item.name) | 305 | logging.error("%s's format is not supported or harmless", item.name) |
| 312 | if os.path.splitext(path)[1] not in parser.NOMETA: | 306 | if os.path.splitext(path)[1] not in parser.NOMETA: |
| 313 | if not list_unsupported: | 307 | if not list_unsupported: |
| 314 | return False | 308 | return False |
| @@ -334,7 +328,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 334 | if meta: | 328 | if meta: |
| 335 | current_meta['file'] = str(meta) | 329 | current_meta['file'] = str(meta) |
| 336 | else: | 330 | else: |
| 337 | logging.error('%s\'s format is not supported or harmless' % item.name) | 331 | logging.error("%s's format is not supported or harmless", item.name) |
| 338 | 332 | ||
| 339 | if not self.is_file_clean(item): # if there is meta | 333 | if not self.is_file_clean(item): # if there is meta |
| 340 | current_meta['mtime'] = item.mtime | 334 | current_meta['mtime'] = item.mtime |
