summaryrefslogtreecommitdiff
path: root/cli.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xcli.py44
1 files changed, 14 insertions, 30 deletions
diff --git a/cli.py b/cli.py
index 3ebe969..f2bec52 100755
--- a/cli.py
+++ b/cli.py
@@ -6,33 +6,30 @@
6import sys 6import sys
7from lib import mat 7from lib import mat
8import optparse 8import optparse
9import hachoir_core
10 9
11__version__ = '0.1' 10__version__ = '0.1'
12 11
13def parse(): 12def 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
32def display_version(*args): 30def 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
38def list_meta(class_file, filename): 35def 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
46def is_clean(class_file, filename): 43def 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
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
77def main(): 63def 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