From f3f757ee70a50bed0f66e8807c7b0ad7db83dc61 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 11 Jul 2011 15:09:25 +0200 Subject: Revert to argparse --- cli.py | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'cli.py') diff --git a/cli.py b/cli.py index a19b8ce..295e90c 100755 --- a/cli.py +++ b/cli.py @@ -5,35 +5,31 @@ import sys from lib import mat -import optparse +import argparse import hachoir_core __version__ = '0.1' def parse(): - parser = optparse.OptionParser(usage='%prog [options] filename') - parser.add_option('--backup', '-b', action='store_true', default=False, - help='Keep a backup copy') - parser.add_option('--check', '-c', action='store_true', default=False, - help='Check if a file is free of harmfull metadatas') - parser.add_option('--display', '-d', action='store_true', default=False, - help='List all the meta of a file without removing them') - parser.add_option('--ugly', '-u', action='store_true', default=False, - help='Remove harmful meta, but loss can occure') - parser.add_option('--version', '-v', action='callback', - callback=display_version, help='Display version and exit') + parser = argparse.ArgumentParser(version=__version__, + description="Metadata Anonymisation Toolkit - CLI %s" % __version__) - values, arguments = parser.parse_args() - if not arguments: - parser.print_help() - sys.exit(0) - return values, arguments + #list and check clean are mutually exclusives + group = parser.add_mutually_exclusive_group() -def display_version(*args): - print('Metadata Anonymisation Toolkit version %s') % mat.__version__ - print('CLI version %s') % __version__ - print('Hachoir version %s') % hachoir_core.__version__ - sys.exit(0) + group.add_argument('--display', '-d', action='store_true', default=False, + dest='display', help='List all the meta of a file') + group.add_argument('--check', '-c', action='store_true', default=False, + dest='check', help='Check if a file is free of harmfull metadatas') + + parser.add_argument('--backup', '-b', action='store_true', default=False, + dest='backup', help='Keep a backup copy') + parser.add_argument('--ugly', '-u', action='store_true', default=False, + dest='ugly', help='Remove harmful meta but information loss may occure') + parser.add_argument('filelist', action='store', type=str, nargs='+', + metavar='files', help='File(s) to process') + + return parser.parse_args() def list_meta(class_file, filename): ''' @@ -78,7 +74,7 @@ def clean_meta_ugly(class_file, filename): print('%s cleaned' % filename) def main(): - args, filenames = parse() + args = parse() #func receive the function correponding to the options given as parameters if args.display is True: #only print metadatas @@ -90,7 +86,7 @@ def main(): else: #clean the file func = clean_meta - for filename in filenames: + for filename in args.filelist: class_file = mat.create_class_file(filename, args.backup) if class_file is not None: func(class_file, filename) -- cgit v1.3