diff options
Diffstat (limited to '')
| -rwxr-xr-x | cli.py | 44 |
1 files changed, 14 insertions, 30 deletions
| @@ -6,33 +6,30 @@ | |||
| 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 | ||
| 10 | 9 | ||
| 11 | __version__ = '0.1' | 10 | __version__ = '0.1' |
| 12 | 11 | ||
| 13 | def parse(): | 12 | def parse(): |
| 14 | parser = optparse.OptionParser(usage='%prog [options] filename') | 13 | parser = optparse.OptionParser(usage='%prog [options] filename') |
| 15 | parser.add_option('--backup', '-b', action='store_true', default=False, | 14 | common = optparse.OptionGroup(parser, 'Metadata Anonymisation Toolkit - CLI') |
| 16 | help='Keep a backup copy') | 15 | common.add_option('--display', '-d', action='store_true', default=False, |
| 17 | parser.add_option('--check', '-c', action='store_true', default=False, | ||
| 18 | help='Check if a file is free of harmfull metadatas') | ||
| 19 | parser.add_option('--display', '-d', action='store_true', default=False, | ||
| 20 | help='List all the meta of a file without removing them') | 16 | help='List all the meta of a file without removing them') |
| 21 | parser.add_option('--ugly', '-u', action='store_true', default=False, | 17 | common.add_option('--check', '-c', action='store_true', default=False, |
| 22 | help='Remove harmful meta, but loss can occure') | 18 | help='Check if a file is free of harmfull metadatas') |
| 23 | parser.add_option('--version', '-v', action='callback', | 19 | common.add_option('--version', action='callback', callback=displayVersion, |
| 24 | callback=display_version, help='Display version and exit') | 20 | help='Display version and exit') |
| 21 | |||
| 22 | parser.add_option_group(common) | ||
| 25 | 23 | ||
| 26 | values, arguments = parser.parse_args() | 24 | values, arguments = parser.parse_args() |
| 27 | if not arguments: | 25 | if not arguments: |
| 28 | parser.print_help() | 26 | parser.print_help() |
| 29 | sys.exit(0) | 27 | sys.exit(1) |
| 30 | return values, arguments | 28 | return values, arguments |
| 31 | 29 | ||
| 32 | def display_version(*args): | 30 | def displayVersion(): |
| 33 | print('Metadata Anonymisation Toolkit version %s') % mat.__version__ | 31 | print('Metadata Anonymisation Toolkit - CLI %s') % __version__ |
| 34 | print('CLI version %s') % __version__ | 32 | print('Hachoir library version %s') % hachoir_core.__version__ |
| 35 | print('Hachoir version %s') % hachoir_core.__version__ | ||
| 36 | sys.exit(0) | 33 | sys.exit(0) |
| 37 | 34 | ||
| 38 | def list_meta(class_file, filename): | 35 | def list_meta(class_file, filename): |
| @@ -41,7 +38,7 @@ def list_meta(class_file, filename): | |||
| 41 | ''' | 38 | ''' |
| 42 | print('[+] File %s :' % filename) | 39 | print('[+] File %s :' % filename) |
| 43 | for key, value in class_file.get_meta().iteritems(): | 40 | for key, value in class_file.get_meta().iteritems(): |
| 44 | print(key + ' : ' + value) | 41 | print key + ' : ' + value |
| 45 | 42 | ||
| 46 | def is_clean(class_file, filename): | 43 | def is_clean(class_file, filename): |
| 47 | ''' | 44 | ''' |
| @@ -63,17 +60,6 @@ def clean_meta(class_file, filename): | |||
| 63 | class_file.remove_all() | 60 | class_file.remove_all() |
| 64 | print('%s cleaned !' % filename) | 61 | print('%s cleaned !' % filename) |
| 65 | 62 | ||
| 66 | def clean_meta_ugly(class_file, filename): | ||
| 67 | ''' | ||
| 68 | Clean the file 'filename', ugly way | ||
| 69 | ''' | ||
| 70 | print('[+] Cleaning %s' % filename) | ||
| 71 | if class_file.is_clean(): | ||
| 72 | print('%s is already clean' % filename) | ||
| 73 | else: | ||
| 74 | class_file.remove_all_ugly() | ||
| 75 | print('%s cleaned' % filename) | ||
| 76 | |||
| 77 | def main(): | 63 | def main(): |
| 78 | args, filenames = parse() | 64 | args, filenames = parse() |
| 79 | 65 | ||
| @@ -82,13 +68,11 @@ def main(): | |||
| 82 | func = list_meta | 68 | func = list_meta |
| 83 | elif args.check is True: #only check if the file is clean | 69 | elif args.check is True: #only check if the file is clean |
| 84 | func = is_clean | 70 | func = is_clean |
| 85 | elif args.ugly is True: #destructive anonymisation method | ||
| 86 | func = clean_meta_ugly | ||
| 87 | else: #clean the file | 71 | else: #clean the file |
| 88 | func = clean_meta | 72 | func = clean_meta |
| 89 | 73 | ||
| 90 | for filename in filenames: | 74 | for filename in filenames: |
| 91 | class_file = mat.create_class_file(filename, args.backup) | 75 | class_file = mat.create_class_file(filename) |
| 92 | func(class_file, filename) | 76 | func(class_file, filename) |
| 93 | print('\n') | 77 | print('\n') |
| 94 | 78 | ||
