From 7189c9997fad6b8d3b90272c8d12bc7437fdb5e5 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 23 Jun 2011 20:08:07 +0200 Subject: Polishing the argument parsing process, fix the display_version function --- cli.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'cli.py') diff --git a/cli.py b/cli.py index 1a8713d..3ebe969 100755 --- a/cli.py +++ b/cli.py @@ -6,33 +6,33 @@ import sys from lib import mat import optparse +import hachoir_core __version__ = '0.1' def parse(): parser = optparse.OptionParser(usage='%prog [options] filename') - common = optparse.OptionGroup(parser, 'Metadata Anonymisation Toolkit - CLI') - common.add_option('--display', '-d', action='store_true', default=False, - help='List all the meta of a file without removing them') - common.add_option('--check', '-c', action='store_true', default=False, - help='Check if a file is free of harmfull metadatas') - common.add_option('--version', action='callback', callback=displayVersion, - help='Display version and exit') - common.add_option('--backup', '-b', action='store_true', default=False, + parser.add_option('--backup', '-b', action='store_true', default=False, help='Keep a backup copy') - common.add_option('--ugly', '-u', action='store_true', default=False, - help='Remove harmful meta, but with loss') - parser.add_option_group(common) + 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') values, arguments = parser.parse_args() if not arguments: parser.print_help() - sys.exit(1) + sys.exit(0) return values, arguments -def displayVersion(): - print('Metadata Anonymisation Toolkit - CLI %s') % __version__ - print('Hachoir library version %s') % hachoir_core.__version__ +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) def list_meta(class_file, filename): @@ -41,7 +41,7 @@ def list_meta(class_file, filename): ''' print('[+] File %s :' % filename) for key, value in class_file.get_meta().iteritems(): - print key + ' : ' + value + print(key + ' : ' + value) def is_clean(class_file, filename): ''' @@ -72,8 +72,7 @@ def clean_meta_ugly(class_file, filename): print('%s is already clean' % filename) else: class_file.remove_all_ugly() - print('%s cleaned !' % filename) - + print('%s cleaned' % filename) def main(): args, filenames = parse() @@ -83,7 +82,7 @@ def main(): func = list_meta elif args.check is True: #only check if the file is clean func = is_clean - elif args.ugly is True: + elif args.ugly is True: #destructive anonymisation method func = clean_meta_ugly else: #clean the file func = clean_meta -- cgit v1.3