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/mat.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/mat.py')
| -rw-r--r-- | libmat/mat.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/libmat/mat.py b/libmat/mat.py index df607a5..42357d6 100644 --- a/libmat/mat.py +++ b/libmat/mat.py | |||
| @@ -119,7 +119,7 @@ def secure_remove(filename): | |||
| 119 | try: # I want the file removed, even if it's read-only | 119 | try: # I want the file removed, even if it's read-only |
| 120 | os.chmod(filename, 220) | 120 | os.chmod(filename, 220) |
| 121 | except OSError: | 121 | except OSError: |
| 122 | logging.error('Unable to add write rights to %s' % filename) | 122 | logging.error('Unable to add write rights to %s', filename) |
| 123 | raise libmat.exceptions.UnableToWriteFile | 123 | raise libmat.exceptions.UnableToWriteFile |
| 124 | 124 | ||
| 125 | try: | 125 | try: |
| @@ -131,12 +131,12 @@ def secure_remove(filename): | |||
| 131 | else: | 131 | else: |
| 132 | raise OSError | 132 | raise OSError |
| 133 | except OSError: | 133 | except OSError: |
| 134 | logging.error('Unable to securely remove %s' % filename) | 134 | logging.error('Unable to securely remove %s', filename) |
| 135 | 135 | ||
| 136 | try: | 136 | try: |
| 137 | os.remove(filename) | 137 | os.remove(filename) |
| 138 | except OSError: | 138 | except OSError: |
| 139 | logging.error('Unable to remove %s' % filename) | 139 | logging.error('Unable to remove %s', filename) |
| 140 | raise libmat.exceptions.UnableToRemoveFile | 140 | raise libmat.exceptions.UnableToRemoveFile |
| 141 | 141 | ||
| 142 | return True | 142 | return True |
| @@ -150,13 +150,13 @@ def create_class_file(name, backup, **kwargs): | |||
| 150 | :param bool backup: shell the file be backuped? | 150 | :param bool backup: shell the file be backuped? |
| 151 | """ | 151 | """ |
| 152 | if not os.path.isfile(name): # check if the file exists | 152 | if not os.path.isfile(name): # check if the file exists |
| 153 | logging.error('%s is not a valid file' % name) | 153 | logging.error('%s is not a valid file', name) |
| 154 | return None | 154 | return None |
| 155 | elif not os.access(name, os.R_OK): # check read permissions | 155 | elif not os.access(name, os.R_OK): # check read permissions |
| 156 | logging.error('%s is is not readable' % name) | 156 | logging.error('%s is is not readable', name) |
| 157 | return None | 157 | return None |
| 158 | elif not os.path.getsize(name): # check if the file is not empty (hachoir crash on empty files) | 158 | elif not os.path.getsize(name): # check if the file is not empty (hachoir crash on empty files) |
| 159 | logging.error('%s is empty' % name) | 159 | logging.error('%s is empty', name) |
| 160 | return None | 160 | return None |
| 161 | 161 | ||
| 162 | try: | 162 | try: |
| @@ -166,11 +166,11 @@ def create_class_file(name, backup, **kwargs): | |||
| 166 | 166 | ||
| 167 | parser = hachoir_parser.createParser(filename) | 167 | parser = hachoir_parser.createParser(filename) |
| 168 | if not parser: | 168 | if not parser: |
| 169 | logging.info('Unable to parse %s with hachoir' % filename) | 169 | logging.info('Unable to parse %s with hachoir', filename) |
| 170 | 170 | ||
| 171 | mime = mimetypes.guess_type(name)[0] | 171 | mime = mimetypes.guess_type(name)[0] |
| 172 | if not mime: | 172 | if not mime: |
| 173 | logging.info('Unable to find mimetype of %s' % filename) | 173 | logging.info('Unable to find mimetype of %s', filename) |
| 174 | return None | 174 | return None |
| 175 | 175 | ||
| 176 | if mime.startswith('application/vnd.oasis.opendocument'): | 176 | if mime.startswith('application/vnd.oasis.opendocument'): |
| @@ -183,7 +183,7 @@ def create_class_file(name, backup, **kwargs): | |||
| 183 | try: | 183 | try: |
| 184 | stripper_class = strippers.STRIPPERS[mime] | 184 | stripper_class = strippers.STRIPPERS[mime] |
| 185 | except KeyError: | 185 | except KeyError: |
| 186 | logging.info('Don\'t have stripper for %s format' % mime) | 186 | logging.info('Don\'t have stripper for %s format', mime) |
| 187 | return None | 187 | return None |
| 188 | 188 | ||
| 189 | return stripper_class(filename, parser, mime, backup, is_writable, **kwargs) | 189 | return stripper_class(filename, parser, mime, backup, is_writable, **kwargs) |
