diff options
| author | jvoisin | 2011-06-23 20:08:07 +0200 |
|---|---|---|
| committer | jvoisin | 2011-06-23 20:08:07 +0200 |
| commit | 7189c9997fad6b8d3b90272c8d12bc7437fdb5e5 (patch) | |
| tree | 15a6fe89907327653a7c68bbc488fd312372da57 /cli.py | |
| parent | e163520a130145496ceeeeeb94d950f17e7fd76e (diff) | |
Polishing the argument parsing process, fix the display_version function
Diffstat (limited to 'cli.py')
| -rwxr-xr-x | cli.py | 37 |
1 files changed, 18 insertions, 19 deletions
| @@ -6,33 +6,33 @@ | |||
| 6 | import sys | 6 | import sys |
| 7 | from lib import mat | 7 | from lib import mat |
| 8 | import optparse | 8 | import optparse |
| 9 | import hachoir_core | ||
| 9 | 10 | ||
| 10 | __version__ = '0.1' | 11 | __version__ = '0.1' |
| 11 | 12 | ||
| 12 | def parse(): | 13 | def parse(): |
| 13 | parser = optparse.OptionParser(usage='%prog [options] filename') | 14 | parser = optparse.OptionParser(usage='%prog [options] filename') |
| 14 | common = optparse.OptionGroup(parser, 'Metadata Anonymisation Toolkit - CLI') | 15 | parser.add_option('--backup', '-b', action='store_true', default=False, |
| 15 | common.add_option('--display', '-d', action='store_true', default=False, | ||
| 16 | help='List all the meta of a file without removing them') | ||
| 17 | common.add_option('--check', '-c', action='store_true', default=False, | ||
| 18 | help='Check if a file is free of harmfull metadatas') | ||
| 19 | common.add_option('--version', action='callback', callback=displayVersion, | ||
| 20 | help='Display version and exit') | ||
| 21 | common.add_option('--backup', '-b', action='store_true', default=False, | ||
| 22 | help='Keep a backup copy') | 16 | help='Keep a backup copy') |
| 23 | common.add_option('--ugly', '-u', action='store_true', default=False, | 17 | parser.add_option('--check', '-c', action='store_true', default=False, |
| 24 | help='Remove harmful meta, but with loss') | 18 | help='Check if a file is free of harmfull metadatas') |
| 25 | parser.add_option_group(common) | 19 | parser.add_option('--display', '-d', action='store_true', default=False, |
| 20 | help='List all the meta of a file without removing them') | ||
| 21 | parser.add_option('--ugly', '-u', action='store_true', default=False, | ||
| 22 | help='Remove harmful meta, but loss can occure') | ||
| 23 | parser.add_option('--version', '-v', action='callback', | ||
| 24 | callback=display_version, help='Display version and exit') | ||
| 26 | 25 | ||
| 27 | values, arguments = parser.parse_args() | 26 | values, arguments = parser.parse_args() |
| 28 | if not arguments: | 27 | if not arguments: |
| 29 | parser.print_help() | 28 | parser.print_help() |
| 30 | sys.exit(1) | 29 | sys.exit(0) |
| 31 | return values, arguments | 30 | return values, arguments |
| 32 | 31 | ||
| 33 | def displayVersion(): | 32 | def display_version(*args): |
| 34 | print('Metadata Anonymisation Toolkit - CLI %s') % __version__ | 33 | print('Metadata Anonymisation Toolkit version %s') % mat.__version__ |
| 35 | print('Hachoir library version %s') % hachoir_core.__version__ | 34 | print('CLI version %s') % __version__ |
| 35 | print('Hachoir version %s') % hachoir_core.__version__ | ||
| 36 | sys.exit(0) | 36 | sys.exit(0) |
| 37 | 37 | ||
| 38 | def list_meta(class_file, filename): | 38 | def list_meta(class_file, filename): |
| @@ -41,7 +41,7 @@ def list_meta(class_file, filename): | |||
| 41 | ''' | 41 | ''' |
| 42 | print('[+] File %s :' % filename) | 42 | print('[+] File %s :' % filename) |
| 43 | for key, value in class_file.get_meta().iteritems(): | 43 | for key, value in class_file.get_meta().iteritems(): |
| 44 | print key + ' : ' + value | 44 | print(key + ' : ' + value) |
| 45 | 45 | ||
| 46 | def is_clean(class_file, filename): | 46 | def is_clean(class_file, filename): |
| 47 | ''' | 47 | ''' |
| @@ -72,8 +72,7 @@ def clean_meta_ugly(class_file, filename): | |||
| 72 | print('%s is already clean' % filename) | 72 | print('%s is already clean' % filename) |
| 73 | else: | 73 | else: |
| 74 | class_file.remove_all_ugly() | 74 | class_file.remove_all_ugly() |
| 75 | print('%s cleaned !' % filename) | 75 | print('%s cleaned' % filename) |
| 76 | |||
| 77 | 76 | ||
| 78 | def main(): | 77 | def main(): |
| 79 | args, filenames = parse() | 78 | args, filenames = parse() |
| @@ -83,7 +82,7 @@ def main(): | |||
| 83 | func = list_meta | 82 | func = list_meta |
| 84 | elif args.check is True: #only check if the file is clean | 83 | elif args.check is True: #only check if the file is clean |
| 85 | func = is_clean | 84 | func = is_clean |
| 86 | elif args.ugly is True: | 85 | elif args.ugly is True: #destructive anonymisation method |
| 87 | func = clean_meta_ugly | 86 | func = clean_meta_ugly |
| 88 | else: #clean the file | 87 | else: #clean the file |
| 89 | func = clean_meta | 88 | func = clean_meta |
