From e616d3d3eaa85e82b0de73885cb0c45838585757 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 23 Jun 2011 22:27:10 +0200 Subject: Revert "Revert "Revert "Rewrite the argument parser, add the --backup and the --ugly options""" This reverts commit 83d2ab46e4f974a4ff70edb95b3ae5469e18906f. --- cli.py | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/cli.py b/cli.py index 3ebe969..f2bec52 100755 --- a/cli.py +++ b/cli.py @@ -6,33 +6,30 @@ import sys from lib import mat import optparse -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, + 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') - 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') + 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') + + parser.add_option_group(common) values, arguments = parser.parse_args() if not arguments: parser.print_help() - sys.exit(0) + sys.exit(1) return values, arguments -def display_version(*args): - print('Metadata Anonymisation Toolkit version %s') % mat.__version__ - print('CLI version %s') % __version__ - print('Hachoir version %s') % hachoir_core.__version__ +def displayVersion(): + print('Metadata Anonymisation Toolkit - CLI %s') % __version__ + print('Hachoir library version %s') % hachoir_core.__version__ sys.exit(0) def list_meta(class_file, filename): @@ -41,7 +38,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): ''' @@ -63,17 +60,6 @@ def clean_meta(class_file, filename): class_file.remove_all() print('%s cleaned !' % filename) -def clean_meta_ugly(class_file, filename): - ''' - Clean the file 'filename', ugly way - ''' - print('[+] Cleaning %s' % filename) - if class_file.is_clean(): - print('%s is already clean' % filename) - else: - class_file.remove_all_ugly() - print('%s cleaned' % filename) - def main(): args, filenames = parse() @@ -82,13 +68,11 @@ 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: #destructive anonymisation method - func = clean_meta_ugly else: #clean the file func = clean_meta for filename in filenames: - class_file = mat.create_class_file(filename, args.backup) + class_file = mat.create_class_file(filename) func(class_file, filename) print('\n') -- cgit v1.3