diff options
| author | jvoisin | 2015-07-25 17:14:23 +0200 |
|---|---|---|
| committer | jvoisin | 2015-07-25 17:14:23 +0200 |
| commit | 6ba3e3f20d7d52895bc44f9fc35b068cfce47133 (patch) | |
| tree | 15df2aca17d56d941c6376ef729e0c1fea4c396f /libmat/mat.py | |
| parent | 85e6279d16af063e5150c7cf4bd491185b8ae788 (diff) | |
_MASSIVE_ pep8 revamp
Thank you so much PyCharm
Diffstat (limited to 'libmat/mat.py')
| -rw-r--r-- | libmat/mat.py | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/libmat/mat.py b/libmat/mat.py index 6e56d54..954b9a3 100644 --- a/libmat/mat.py +++ b/libmat/mat.py | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
| 2 | 2 | ||
| 3 | ''' Metadata anonymisation toolkit library | 3 | """ Metadata anonymisation toolkit library |
| 4 | ''' | 4 | """ |
| 5 | 5 | ||
| 6 | import logging | 6 | import logging |
| 7 | import mimetypes | 7 | import mimetypes |
| @@ -18,15 +18,15 @@ import libmat.exceptions | |||
| 18 | __version__ = '0.5.3' | 18 | __version__ = '0.5.3' |
| 19 | __author__ = 'jvoisin' | 19 | __author__ = 'jvoisin' |
| 20 | 20 | ||
| 21 | #Silence | 21 | # Silence |
| 22 | LOGGING_LEVEL = logging.CRITICAL | 22 | LOGGING_LEVEL = logging.CRITICAL |
| 23 | hachoir_core.config.quiet = True | 23 | hachoir_core.config.quiet = True |
| 24 | fname = '' | 24 | fname = '' |
| 25 | 25 | ||
| 26 | #Verbose | 26 | # Verbose |
| 27 | #LOGGING_LEVEL = logging.DEBUG | 27 | # LOGGING_LEVEL = logging.DEBUG |
| 28 | #hachoir_core.config.quiet = False | 28 | # hachoir_core.config.quiet = False |
| 29 | #logname = 'report.log' | 29 | # logname = 'report.log' |
| 30 | 30 | ||
| 31 | logging.basicConfig(filename=fname, level=LOGGING_LEVEL) | 31 | logging.basicConfig(filename=fname, level=LOGGING_LEVEL) |
| 32 | 32 | ||
| @@ -34,10 +34,10 @@ import strippers # this is loaded here because we need LOGGING_LEVEL | |||
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | def get_logo(): | 36 | def get_logo(): |
| 37 | ''' Return the path to the logo | 37 | """ Return the path to the logo |
| 38 | ''' | 38 | """ |
| 39 | if os.path.isfile(os.path.join(os.path.curdir, 'data/mat.png')): | 39 | if os.path.isfile(os.path.join(os.path.curdir, 'data/mat.png')): |
| 40 | return os.path.join(os.path.curdir,'data/mat.png') | 40 | return os.path.join(os.path.curdir, 'data/mat.png') |
| 41 | elif os.path.isfile('/usr/share/pixmaps/mat.png'): | 41 | elif os.path.isfile('/usr/share/pixmaps/mat.png'): |
| 42 | return '/usr/share/pixmaps/mat.png' | 42 | return '/usr/share/pixmaps/mat.png' |
| 43 | elif os.path.isfile('/usr/local/share/pixmaps/mat.png'): | 43 | elif os.path.isfile('/usr/local/share/pixmaps/mat.png'): |
| @@ -45,8 +45,8 @@ def get_logo(): | |||
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | def get_datafile_path(filename): | 47 | def get_datafile_path(filename): |
| 48 | ''' Return the path to the given ressource | 48 | """ Return the path to the given ressource |
| 49 | ''' | 49 | """ |
| 50 | if os.path.isfile(os.path.join(os.path.curdir, 'data', filename)): | 50 | if os.path.isfile(os.path.join(os.path.curdir, 'data', filename)): |
| 51 | return os.path.join(os.path.curdir, 'data', filename) | 51 | return os.path.join(os.path.curdir, 'data', filename) |
| 52 | elif os.path.isfile(os.path.join('/usr/local/share/mat/', filename)): | 52 | elif os.path.isfile(os.path.join('/usr/local/share/mat/', filename)): |
| @@ -56,10 +56,10 @@ def get_datafile_path(filename): | |||
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | def list_supported_formats(): | 58 | def list_supported_formats(): |
| 59 | ''' Return a list of all locally supported fileformat. | 59 | """ Return a list of all locally supported fileformat. |
| 60 | It parses that FORMATS file, and removes locally | 60 | It parses that FORMATS file, and removes locally |
| 61 | non-supported formats. | 61 | non-supported formats. |
| 62 | ''' | 62 | """ |
| 63 | handler = XMLParser() | 63 | handler = XMLParser() |
| 64 | parser = xml.sax.make_parser() | 64 | parser = xml.sax.make_parser() |
| 65 | parser.setContentHandler(handler) | 65 | parser.setContentHandler(handler) |
| @@ -76,9 +76,10 @@ def list_supported_formats(): | |||
| 76 | 76 | ||
| 77 | 77 | ||
| 78 | class XMLParser(xml.sax.handler.ContentHandler): | 78 | class XMLParser(xml.sax.handler.ContentHandler): |
| 79 | ''' Parse the supported format xml, and return a corresponding | 79 | """ Parse the supported format xml, and return a corresponding |
| 80 | list of dict | 80 | list of dict |
| 81 | ''' | 81 | """ |
| 82 | |||
| 82 | def __init__(self): | 83 | def __init__(self): |
| 83 | self.dict = {} | 84 | self.dict = {} |
| 84 | self.list = [] | 85 | self.list = [] |
| @@ -86,15 +87,15 @@ class XMLParser(xml.sax.handler.ContentHandler): | |||
| 86 | self.between = False | 87 | self.between = False |
| 87 | 88 | ||
| 88 | def startElement(self, name, attrs): | 89 | def startElement(self, name, attrs): |
| 89 | ''' Called when entering into xml tag | 90 | """ Called when entering into xml tag |
| 90 | ''' | 91 | """ |
| 91 | self.between = True | 92 | self.between = True |
| 92 | self.key = name | 93 | self.key = name |
| 93 | self.content = '' | 94 | self.content = '' |
| 94 | 95 | ||
| 95 | def endElement(self, name): | 96 | def endElement(self, name): |
| 96 | ''' Called when exiting a xml tag | 97 | """ Called when exiting a xml tag |
| 97 | ''' | 98 | """ |
| 98 | if name == 'format': # leaving a fileformat section | 99 | if name == 'format': # leaving a fileformat section |
| 99 | self.list.append(self.dict.copy()) | 100 | self.list.append(self.dict.copy()) |
| 100 | self.dict.clear() | 101 | self.dict.clear() |
| @@ -104,15 +105,15 @@ class XMLParser(xml.sax.handler.ContentHandler): | |||
| 104 | self.between = False | 105 | self.between = False |
| 105 | 106 | ||
| 106 | def characters(self, characters): | 107 | def characters(self, characters): |
| 107 | ''' Concatenate the content between opening and closing tags | 108 | """ Concatenate the content between opening and closing tags |
| 108 | ''' | 109 | """ |
| 109 | if self.between: | 110 | if self.between: |
| 110 | self.content += characters | 111 | self.content += characters |
| 111 | 112 | ||
| 112 | 113 | ||
| 113 | def secure_remove(filename): | 114 | def secure_remove(filename): |
| 114 | ''' Securely remove the file | 115 | """ Securely remove the file |
| 115 | ''' | 116 | """ |
| 116 | # I want the file removed, even if it's ro | 117 | # I want the file removed, even if it's ro |
| 117 | try: | 118 | try: |
| 118 | os.chmod(filename, 220) | 119 | os.chmod(filename, 220) |
| @@ -141,9 +142,9 @@ def secure_remove(filename): | |||
| 141 | 142 | ||
| 142 | 143 | ||
| 143 | def create_class_file(name, backup, **kwargs): | 144 | def create_class_file(name, backup, **kwargs): |
| 144 | ''' Return a $FILETYPEStripper() class, | 145 | """ Return a $FILETYPEStripper() class, |
| 145 | corresponding to the filetype of the given file | 146 | corresponding to the filetype of the given file |
| 146 | ''' | 147 | """ |
| 147 | if not os.path.isfile(name): # check if the file exists | 148 | if not os.path.isfile(name): # check if the file exists |
| 148 | logging.error('%s is not a valid file' % name) | 149 | logging.error('%s is not a valid file' % name) |
| 149 | return None | 150 | return None |
| @@ -153,7 +154,7 @@ def create_class_file(name, backup, **kwargs): | |||
| 153 | return None | 154 | return None |
| 154 | 155 | ||
| 155 | if not os.path.getsize(name): | 156 | if not os.path.getsize(name): |
| 156 | #check if the file is not empty (hachoir crash on empty files) | 157 | # check if the file is not empty (hachoir crash on empty files) |
| 157 | logging.error('%s is empty' % name) | 158 | logging.error('%s is empty' % name) |
| 158 | return None | 159 | return None |
| 159 | 160 | ||
