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