summaryrefslogtreecommitdiff
path: root/cli.py
diff options
context:
space:
mode:
authorjvoisin2011-06-10 01:29:29 +0200
committerjvoisin2011-06-10 01:29:29 +0200
commitc308cf7daaa4fa46377e2df0f2e9a397981e19b2 (patch)
treef016ce17cd6747acc068a7d2fc5093d1bd96fa9e /cli.py
parentf7082a21d6511c5069fbb9ff186ce22f3e22fed7 (diff)
The current version is (mostly) working
Diffstat (limited to 'cli.py')
-rw-r--r--cli.py77
1 files changed, 76 insertions, 1 deletions
diff --git a/cli.py b/cli.py
index d249917..fedb40c 100644
--- a/cli.py
+++ b/cli.py
@@ -3,7 +3,82 @@
3 Metadata anonymisation toolkit 3 Metadata anonymisation toolkit
4""" 4"""
5 5
6import lib
7import sys 6import sys
7import mat
8import argparse
8 9
10__version__ = "0.1"
9 11
12def parsing():
13 '''
14 Parse the arguments,
15 and returns a dict
16 '''
17 parser = argparse.ArgumentParser(version=__version__,
18 description="Metadata Anonymisation Toolkit - CLI %s" % __version__)
19
20 #list and check clean are mutually exclusives
21 group = parser.add_mutually_exclusive_group()
22
23 #list meta
24 group.add_argument('--print-meta', '-p', action="store_true", default=False,
25 dest='just_list', help='List all the meta of a file,\
26 without removing them')
27
28 #check if the file is clean
29 group.add_argument('--check-clean', '-c', action="store_true",
30 default=False, dest='just_check',
31 help='Check if a file is clean of harmfull metadatas')
32
33 #list of files to process
34 parser.add_argument('filelist', action="store", type=str, nargs="+",
35 metavar='file', help='File(s) to process')
36
37 return parser.parse_args()
38
39def list_meta(class_file, filename):
40 '''
41 Print all the meta of "filename" on stdout
42 '''
43 print("[+] File %s :" % filename)
44 for key, item in class_file.get_meta().iteritems():
45 print("\t%s : %s" % (key, item) )
46
47def is_clean(class_file, filename):
48 '''
49 Say if "filename" is clean or not
50 '''
51 if class_file.is_clean():
52 print("[+] %s is clean" % filename)
53 else:
54 print("[+] %s is not clean" % filename)
55
56def clean_meta(class_file, filename):
57 '''
58 Clean the file "filename"
59 '''
60 print("[+] Cleaning %s" % filename)
61 if class_file.is_clean():
62 print("%s is already clean" % filename)
63 else:
64 class_file.remove_all()
65 print("%s cleaned !" % filename)
66
67def main():
68 args = parsing()
69
70 #func receive the function correponding to the options given as parameters
71 if args.just_list is True: #only print metadatas
72 func = list_meta
73 elif args.just_check is True: #only check if the file is clean
74 func = is_clean
75 else: #clean the file
76 func = clean_meta
77
78 for filename in args.filelist:
79 class_file = mat.create_class_file(filename)
80 func(class_file, filename)
81 print("\n")
82
83if __name__ == '__main__':
84 main()