diff options
| author | jvoisin | 2011-07-20 15:22:27 +0200 |
|---|---|---|
| committer | jvoisin | 2011-07-20 15:22:27 +0200 |
| commit | aff8bc18ec06ca574ec616027df2d88907cd9e38 (patch) | |
| tree | a6ffb0ad11f51902734ef38d5c1c8cd3768abfe2 /cli.py | |
| parent | 538e63349b4c1747e97688589f3ad827e6e213c6 (diff) | |
Revert "Revert to argparse" for python2.6
This reverts commit f3f757ee70a50bed0f66e8807c7b0ad7db83dc61.
Diffstat (limited to 'cli.py')
| -rwxr-xr-x | cli.py | 44 |
1 files changed, 24 insertions, 20 deletions
| @@ -5,31 +5,35 @@ | |||
| 5 | 5 | ||
| 6 | import sys | 6 | import sys |
| 7 | from lib import mat | 7 | from lib import mat |
| 8 | import argparse | 8 | import optparse |
| 9 | import hachoir_core | 9 | import hachoir_core |
| 10 | 10 | ||
| 11 | __version__ = '0.1' | 11 | __version__ = '0.1' |
| 12 | 12 | ||
| 13 | def parse(): | 13 | def 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, | 32 | def 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 | ||
| 34 | def list_meta(class_file, filename): | 38 | def 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 | ||
| 76 | def main(): | 80 | def 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) |
