diff options
| -rwxr-xr-x | cli.py | 30 |
1 files changed, 18 insertions, 12 deletions
| @@ -27,6 +27,8 @@ def parse(): | |||
| 27 | help='Check if a file is free of harmfull metadatas') | 27 | help='Check if a file is free of harmfull metadatas') |
| 28 | parser.add_option('--display', '-d', action='store_true', default=False, | 28 | parser.add_option('--display', '-d', action='store_true', default=False, |
| 29 | help='List all the meta of a file without removing them') | 29 | help='List all the meta of a file without removing them') |
| 30 | parser.add_option('--force', '-f', action='store_true', default=False, | ||
| 31 | help='Don\'t check if files are clean before cleaning') | ||
| 30 | parser.add_option('--list', '-l', action='store_true', default=False, | 32 | parser.add_option('--list', '-l', action='store_true', default=False, |
| 31 | help='List all supported fileformat') | 33 | help='List all supported fileformat') |
| 32 | parser.add_option('--ugly', '-u', action='store_true', default=False, | 34 | parser.add_option('--ugly', '-u', action='store_true', default=False, |
| @@ -51,19 +53,23 @@ def display_version(*_): | |||
| 51 | sys.exit(0) | 53 | sys.exit(0) |
| 52 | 54 | ||
| 53 | 55 | ||
| 54 | def list_meta(class_file, filename): | 56 | def list_meta(class_file, filename, force): |
| 55 | ''' | 57 | ''' |
| 56 | Print all the meta of 'filename' on stdout | 58 | Print all the meta of 'filename' on stdout |
| 57 | ''' | 59 | ''' |
| 58 | print('[+] File %s :' % filename) | 60 | print('[+] File %s :' % filename) |
| 59 | if class_file.is_clean(): | 61 | if force is False and class_file.is_clean(): |
| 60 | print('No harmful meta found') | 62 | print('No harmful meta found') |
| 61 | else: | 63 | else: |
| 62 | for key, value in class_file.get_meta().iteritems(): | 64 | meta = class_file.get_meta() |
| 63 | print(key + ' : ' + str(value)) | 65 | if meta is None: |
| 66 | print('No harmful meta found') | ||
| 67 | else: | ||
| 68 | for key, value in class_file.get_meta().iteritems(): | ||
| 69 | print(key + ' : ' + str(value)) | ||
| 64 | 70 | ||
| 65 | 71 | ||
| 66 | def is_clean(class_file, filename): | 72 | def is_clean(class_file, filename, force): |
| 67 | ''' | 73 | ''' |
| 68 | Say if 'filename' is clean or not | 74 | Say if 'filename' is clean or not |
| 69 | ''' | 75 | ''' |
| @@ -73,24 +79,24 @@ def is_clean(class_file, filename): | |||
| 73 | print('[+] %s is not clean' % filename) | 79 | print('[+] %s is not clean' % filename) |
| 74 | 80 | ||
| 75 | 81 | ||
| 76 | def clean_meta(class_file, filename): | 82 | def clean_meta(class_file, filename, force): |
| 77 | ''' | 83 | ''' |
| 78 | Clean the file 'filename' | 84 | Clean the file 'filename' |
| 79 | ''' | 85 | ''' |
| 80 | print('[+] Cleaning %s' % filename) | 86 | print('[+] Cleaning %s' % filename) |
| 81 | if class_file.is_clean(): | 87 | if force is False and class_file.is_clean(): |
| 82 | print('%s is already clean' % filename) | 88 | print('%s is already clean' % filename) |
| 83 | else: | 89 | else: |
| 84 | class_file.remove_all() | 90 | class_file.remove_all() |
| 85 | print('%s cleaned !' % filename) | 91 | print('%s cleaned !' % filename) |
| 86 | 92 | ||
| 87 | 93 | ||
| 88 | def clean_meta_ugly(class_file, filename): | 94 | def clean_meta_ugly(class_file, filename, force): |
| 89 | ''' | 95 | ''' |
| 90 | Clean the file 'filename', ugly way | 96 | Clean the file 'filename', ugly way |
| 91 | ''' | 97 | ''' |
| 92 | print('[+] Cleaning %s' % filename) | 98 | print('[+] Cleaning %s' % filename) |
| 93 | if class_file.is_clean(): | 99 | if force is False and class_file.is_clean(): |
| 94 | print('%s is already clean' % filename) | 100 | print('%s is already clean' % filename) |
| 95 | else: | 101 | else: |
| 96 | class_file.remove_all_ugly() | 102 | class_file.remove_all_ugly() |
| @@ -104,8 +110,8 @@ def list_supported(): | |||
| 104 | handler = mat.XMLParser() | 110 | handler = mat.XMLParser() |
| 105 | parser = xml.sax.make_parser() | 111 | parser = xml.sax.make_parser() |
| 106 | parser.setContentHandler(handler) | 112 | parser.setContentHandler(handler) |
| 107 | with open('FORMATS', 'r') as f: | 113 | with open('FORMATS', 'r') as xmlfile: |
| 108 | parser.parse(f) | 114 | parser.parse(xmlfile) |
| 109 | 115 | ||
| 110 | for item in handler.list: | 116 | for item in handler.list: |
| 111 | print('%s (%s)' % (item['name'], item['extension'])) | 117 | print('%s (%s)' % (item['name'], item['extension'])) |
| @@ -139,7 +145,7 @@ def main(): | |||
| 139 | class_file = mat.create_class_file(filename, args.backup, | 145 | class_file = mat.create_class_file(filename, args.backup, |
| 140 | args.add2archive) | 146 | args.add2archive) |
| 141 | if class_file is not None: | 147 | if class_file is not None: |
| 142 | func(class_file, filename) | 148 | func(class_file, filename, args.force) |
| 143 | 149 | ||
| 144 | if __name__ == '__main__': | 150 | if __name__ == '__main__': |
| 145 | main() | 151 | main() |
