summaryrefslogtreecommitdiff
path: root/cli.py
diff options
context:
space:
mode:
authorjvoisin2011-07-11 15:09:25 +0200
committerjvoisin2011-07-11 15:09:25 +0200
commitf3f757ee70a50bed0f66e8807c7b0ad7db83dc61 (patch)
tree6fc22bd700d82beff66aeb7c9c64f491e7542f83 /cli.py
parent154ef354cfa4c36958faa633c226211729bffeda (diff)
Revert to argparse
Diffstat (limited to 'cli.py')
-rwxr-xr-xcli.py44
1 files changed, 20 insertions, 24 deletions
diff --git a/cli.py b/cli.py
index a19b8ce..295e90c 100755
--- a/cli.py
+++ b/cli.py
@@ -5,35 +5,31 @@
5 5
6import sys 6import sys
7from lib import mat 7from lib import mat
8import optparse 8import argparse
9import hachoir_core 9import hachoir_core
10 10
11__version__ = '0.1' 11__version__ = '0.1'
12 12
13def parse(): 13def parse():
14 parser = optparse.OptionParser(usage='%prog [options] filename') 14 parser = argparse.ArgumentParser(version=__version__,
15 parser.add_option('--backup', '-b', action='store_true', default=False, 15 description="Metadata Anonymisation Toolkit - CLI %s" % __version__)
16 help='Keep a backup copy')
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')
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')
25 16
26 values, arguments = parser.parse_args() 17 #list and check clean are mutually exclusives
27 if not arguments: 18 group = parser.add_mutually_exclusive_group()
28 parser.print_help()
29 sys.exit(0)
30 return values, arguments
31 19
32def display_version(*args): 20 group.add_argument('--display', '-d', action='store_true', default=False,
33 print('Metadata Anonymisation Toolkit version %s') % mat.__version__ 21 dest='display', help='List all the meta of a file')
34 print('CLI version %s') % __version__ 22 group.add_argument('--check', '-c', action='store_true', default=False,
35 print('Hachoir version %s') % hachoir_core.__version__ 23 dest='check', help='Check if a file is free of harmfull metadatas')
36 sys.exit(0) 24
25 parser.add_argument('--backup', '-b', action='store_true', default=False,
26 dest='backup', help='Keep a backup copy')
27 parser.add_argument('--ugly', '-u', action='store_true', default=False,
28 dest='ugly', help='Remove harmful meta but information loss may occure')
29 parser.add_argument('filelist', action='store', type=str, nargs='+',
30 metavar='files', help='File(s) to process')
31
32 return parser.parse_args()
37 33
38def list_meta(class_file, filename): 34def list_meta(class_file, filename):
39 ''' 35 '''
@@ -78,7 +74,7 @@ def clean_meta_ugly(class_file, filename):
78 print('%s cleaned' % filename) 74 print('%s cleaned' % filename)
79 75
80def main(): 76def main():
81 args, filenames = parse() 77 args = parse()
82 78
83 #func receive the function correponding to the options given as parameters 79 #func receive the function correponding to the options given as parameters
84 if args.display is True: #only print metadatas 80 if args.display is True: #only print metadatas
@@ -90,7 +86,7 @@ def main():
90 else: #clean the file 86 else: #clean the file
91 func = clean_meta 87 func = clean_meta
92 88
93 for filename in filenames: 89 for filename in args.filelist:
94 class_file = mat.create_class_file(filename, args.backup) 90 class_file = mat.create_class_file(filename, args.backup)
95 if class_file is not None: 91 if class_file is not None:
96 func(class_file, filename) 92 func(class_file, filename)