diff options
| author | jvoisin | 2011-08-03 19:26:04 +0200 |
|---|---|---|
| committer | jvoisin | 2011-08-03 19:26:04 +0200 |
| commit | 2b3f7d7721ef7040d7b4d5e591cf9b2d3d9740e0 (patch) | |
| tree | 8e741b41709209b5ecb1cf4ca9538aa9596a6e97 /cli.py | |
| parent | d885cd9587a701d880049cb5c1b90a2e75c35338 (diff) | |
Add listing of supported fileformat to cli
Diffstat (limited to 'cli.py')
| -rwxr-xr-x | cli.py | 33 |
1 files changed, 30 insertions, 3 deletions
| @@ -4,10 +4,13 @@ | |||
| 4 | ''' | 4 | ''' |
| 5 | 5 | ||
| 6 | import sys | 6 | import sys |
| 7 | from lib import mat | 7 | import xml.sax |
| 8 | import optparse | 8 | import optparse |
| 9 | |||
| 9 | import hachoir_core | 10 | import hachoir_core |
| 10 | 11 | ||
| 12 | from lib import mat | ||
| 13 | |||
| 11 | __version__ = '0.1' | 14 | __version__ = '0.1' |
| 12 | 15 | ||
| 13 | 16 | ||
| @@ -15,7 +18,7 @@ def parse(): | |||
| 15 | ''' | 18 | ''' |
| 16 | Get, and parse options passed to the program | 19 | Get, and parse options passed to the program |
| 17 | ''' | 20 | ''' |
| 18 | parser = optparse.OptionParser(usage='%prog [options] filename') | 21 | parser = optparse.OptionParser(usage='%prog [options] files') |
| 19 | parser.add_option('--add2archive', '-a', action='store_true', | 22 | parser.add_option('--add2archive', '-a', action='store_true', |
| 20 | default=False, help='Add to outputed archive non-supported filetypes') | 23 | default=False, help='Add to outputed archive non-supported filetypes') |
| 21 | parser.add_option('--backup', '-b', action='store_true', default=False, | 24 | parser.add_option('--backup', '-b', action='store_true', default=False, |
| @@ -24,13 +27,15 @@ def parse(): | |||
| 24 | help='Check if a file is free of harmfull metadatas') | 27 | help='Check if a file is free of harmfull metadatas') |
| 25 | parser.add_option('--display', '-d', action='store_true', default=False, | 28 | parser.add_option('--display', '-d', action='store_true', default=False, |
| 26 | help='List all the meta of a file without removing them') | 29 | help='List all the meta of a file without removing them') |
| 30 | parser.add_option('--list', '-l', action='store_true', default=False, | ||
| 31 | help='List all supported fileformat') | ||
| 27 | parser.add_option('--ugly', '-u', action='store_true', default=False, | 32 | parser.add_option('--ugly', '-u', action='store_true', default=False, |
| 28 | help='Remove harmful meta, but loss can occure') | 33 | help='Remove harmful meta, but loss can occure') |
| 29 | parser.add_option('--version', '-v', action='callback', | 34 | parser.add_option('--version', '-v', action='callback', |
| 30 | callback=display_version, help='Display version and exit') | 35 | callback=display_version, help='Display version and exit') |
| 31 | 36 | ||
| 32 | values, arguments = parser.parse_args() | 37 | values, arguments = parser.parse_args() |
| 33 | if not arguments: | 38 | if not arguments and values.list is False: |
| 34 | parser.print_help() | 39 | parser.print_help() |
| 35 | sys.exit(0) | 40 | sys.exit(0) |
| 36 | return values, arguments | 41 | return values, arguments |
| @@ -92,6 +97,26 @@ def clean_meta_ugly(class_file, filename): | |||
| 92 | print('%s cleaned' % filename) | 97 | print('%s cleaned' % filename) |
| 93 | 98 | ||
| 94 | 99 | ||
| 100 | def list_supported(): | ||
| 101 | ''' | ||
| 102 | Print all supported fileformat, and exit | ||
| 103 | ''' | ||
| 104 | handler = mat.XMLParser() | ||
| 105 | parser = xml.sax.make_parser() | ||
| 106 | parser.setContentHandler(handler) | ||
| 107 | with open('FORMATS', 'r') as f: | ||
| 108 | parser.parse(f) | ||
| 109 | |||
| 110 | for item in handler.list: | ||
| 111 | print('%s (%s)' % (item['name'], item['extension'])) | ||
| 112 | print('\tsupport : ' + item['support']) | ||
| 113 | print('\tmetadata : ' + item['metadata']) | ||
| 114 | print('\tmethod : ' + item['method']) | ||
| 115 | if item['support'] == 'partial': | ||
| 116 | print('\tremaining : ' + item['remaining']) | ||
| 117 | print('\n') | ||
| 118 | sys.exit(0) | ||
| 119 | |||
| 95 | def main(): | 120 | def main(): |
| 96 | ''' | 121 | ''' |
| 97 | main function : get args, and launch the appropriate function | 122 | main function : get args, and launch the appropriate function |
| @@ -105,6 +130,8 @@ def main(): | |||
| 105 | func = is_clean | 130 | func = is_clean |
| 106 | elif args.ugly is True: # destructive anonymisation method | 131 | elif args.ugly is True: # destructive anonymisation method |
| 107 | func = clean_meta_ugly | 132 | func = clean_meta_ugly |
| 133 | elif args.list is True: | ||
| 134 | list_supported() | ||
| 108 | else: # clean the file | 135 | else: # clean the file |
| 109 | func = clean_meta | 136 | func = clean_meta |
| 110 | 137 | ||
