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