diff options
| author | Tails developers | 2013-07-13 10:15:47 +0000 |
|---|---|---|
| committer | jvoisin | 2013-07-13 13:10:53 +0200 |
| commit | 2968a48fd4e015983c3255fd4fc584c649abfd63 (patch) | |
| tree | 013d5599e0e9c9b236d14c653be212182ca4b3a4 | |
| parent | f03dbf33f84e513bdd396fb8e13255fac5834a7d (diff) | |
Include list_supported_formats in the module
| -rw-r--r-- | MAT/mat.py | 19 | ||||
| -rwxr-xr-x | mat | 22 |
2 files changed, 25 insertions, 16 deletions
| @@ -13,7 +13,6 @@ import xml.sax | |||
| 13 | import hachoir_core.cmd_line | 13 | import hachoir_core.cmd_line |
| 14 | import hachoir_parser | 14 | import hachoir_parser |
| 15 | 15 | ||
| 16 | |||
| 17 | __version__ = '0.4' | 16 | __version__ = '0.4' |
| 18 | __author__ = 'jvoisin' | 17 | __author__ = 'jvoisin' |
| 19 | 18 | ||
| @@ -47,6 +46,24 @@ def get_datadir(): | |||
| 47 | elif os.path.isdir('/usr/local/share/mat/'): | 46 | elif os.path.isdir('/usr/local/share/mat/'): |
| 48 | return '/usr/local/share/mat/' | 47 | return '/usr/local/share/mat/' |
| 49 | 48 | ||
| 49 | def list_supported_formats(): | ||
| 50 | ''' | ||
| 51 | Return a list of all localy supported fileformat | ||
| 52 | ''' | ||
| 53 | handler = XMLParser() | ||
| 54 | parser = xml.sax.make_parser() | ||
| 55 | parser.setContentHandler(handler) | ||
| 56 | path = os.path.join(get_datadir(), 'FORMATS') | ||
| 57 | with open(path, 'r') as xmlfile: | ||
| 58 | parser.parse(xmlfile) | ||
| 59 | |||
| 60 | localy_supported = [] | ||
| 61 | for item in handler.list: | ||
| 62 | if strippers.STRIPPERS.has_key(item['mimetype'].split(',')[0]): | ||
| 63 | localy_supported.append(item) | ||
| 64 | |||
| 65 | return localy_supported | ||
| 66 | |||
| 50 | class XMLParser(xml.sax.handler.ContentHandler): | 67 | class XMLParser(xml.sax.handler.ContentHandler): |
| 51 | ''' | 68 | ''' |
| 52 | Parse the supported format xml, and return a corresponding | 69 | Parse the supported format xml, and return a corresponding |
| @@ -102,21 +102,13 @@ def list_supported(): | |||
| 102 | ''' | 102 | ''' |
| 103 | Print all supported fileformat, and exit | 103 | Print all supported fileformat, and exit |
| 104 | ''' | 104 | ''' |
| 105 | handler = mat.XMLParser() | 105 | for item in mat.list_supported_formats(): |
| 106 | parser = xml.sax.make_parser() | 106 | print('%s (%s)' % (item['name'], item['extension'])) |
| 107 | parser.setContentHandler(handler) | 107 | print('\tsupport : ' + item['support']) |
| 108 | path = os.path.join(mat.get_datadir(), 'FORMATS') | 108 | print('\tmetadata : ' + item['metadata']) |
| 109 | with open(path, 'r') as xmlfile: | 109 | print('\tmethod : ' + item['method']) |
| 110 | parser.parse(xmlfile) | 110 | print('\tremaining : ' + item['remaining']) |
| 111 | 111 | print('\n') | |
| 112 | for item in handler.list: | ||
| 113 | if strippers.STRIPPERS.has_key(item['mimetype'].split(',')[0]): | ||
| 114 | print('%s (%s)' % (item['name'], item['extension'])) | ||
| 115 | print('\tsupport : ' + item['support']) | ||
| 116 | print('\tmetadata : ' + item['metadata']) | ||
| 117 | print('\tmethod : ' + item['method']) | ||
| 118 | print('\tremaining : ' + item['remaining']) | ||
| 119 | print('\n') | ||
| 120 | sys.exit(0) | 112 | sys.exit(0) |
| 121 | 113 | ||
| 122 | 114 | ||
