diff options
| author | jvoisin | 2014-02-03 01:00:54 +0000 |
|---|---|---|
| committer | jvoisin | 2014-02-03 01:00:54 +0000 |
| commit | 091a23c46f2bb74ba639f661552430ccd3045f72 (patch) | |
| tree | 5026c28962f7d432f198102cb8f19d12fa61e13f | |
| parent | a67e6ea14c0a4e2b0e976acc57166c827befe4f0 (diff) | |
MAT's cli now returns 1 on failure
| -rwxr-xr-x | mat | 16 |
1 files changed, 12 insertions, 4 deletions
| @@ -73,6 +73,7 @@ def list_meta(class_file, filename, force, add2archive): | |||
| 73 | if meta: | 73 | if meta: |
| 74 | for key, value in class_file.get_meta().iteritems(): | 74 | for key, value in class_file.get_meta().iteritems(): |
| 75 | print('\t' + key + ' : ' + str(value)) | 75 | print('\t' + key + ' : ' + str(value)) |
| 76 | return 0 | ||
| 76 | 77 | ||
| 77 | 78 | ||
| 78 | def is_clean(class_file, filename, force, add2archive): | 79 | def is_clean(class_file, filename, force, add2archive): |
| @@ -83,6 +84,7 @@ def is_clean(class_file, filename, force, add2archive): | |||
| 83 | print('[+] %s is clean' % filename) | 84 | print('[+] %s is clean' % filename) |
| 84 | else: | 85 | else: |
| 85 | print('[+] %s is not clean' % filename) | 86 | print('[+] %s is not clean' % filename) |
| 87 | return 0 | ||
| 86 | 88 | ||
| 87 | 89 | ||
| 88 | def clean_meta(class_file, filename, force, add2archive): | 90 | def clean_meta(class_file, filename, force, add2archive): |
| @@ -91,7 +93,7 @@ def clean_meta(class_file, filename, force, add2archive): | |||
| 91 | ''' | 93 | ''' |
| 92 | if not class_file.is_writable: | 94 | if not class_file.is_writable: |
| 93 | print('[-] %s is not writable' % filename) | 95 | print('[-] %s is not writable' % filename) |
| 94 | return | 96 | return 1 |
| 95 | print('[*] Cleaning %s' % filename) | 97 | print('[*] Cleaning %s' % filename) |
| 96 | if not force and class_file.is_clean(): | 98 | if not force and class_file.is_clean(): |
| 97 | print('[+] %s is already clean' % filename) | 99 | print('[+] %s is already clean' % filename) |
| @@ -105,10 +107,13 @@ def clean_meta(class_file, filename, force, add2archive): | |||
| 105 | 'It contains unsupported filetypes:' % filename) | 107 | 'It contains unsupported filetypes:' % filename) |
| 106 | for i in unsupported_list: | 108 | for i in unsupported_list: |
| 107 | print('- %s' % i) | 109 | print('- %s' % i) |
| 108 | elif class_file.remove_all(): | 110 | return 1 |
| 111 | if class_file.remove_all(): | ||
| 109 | print('[+] %s cleaned !' % filename) | 112 | print('[+] %s cleaned !' % filename) |
| 110 | else: | 113 | else: |
| 111 | print('[-] Unable to clean %s', filename) | 114 | print('[-] Unable to clean %s', filename) |
| 115 | return 1 | ||
| 116 | return 0 | ||
| 112 | 117 | ||
| 113 | 118 | ||
| 114 | def list_supported(): | 119 | def list_supported(): |
| @@ -141,6 +146,7 @@ def main(): | |||
| 141 | else: # clean the file | 146 | else: # clean the file |
| 142 | func = clean_meta | 147 | func = clean_meta |
| 143 | 148 | ||
| 149 | ret = 0 | ||
| 144 | while filenames: | 150 | while filenames: |
| 145 | filename = filenames.pop() | 151 | filename = filenames.pop() |
| 146 | if os.path.isdir(filename): | 152 | if os.path.isdir(filename): |
| @@ -152,9 +158,11 @@ def main(): | |||
| 152 | class_file = mat.create_class_file(filename, args.backup, | 158 | class_file = mat.create_class_file(filename, args.backup, |
| 153 | add2archive=args.add2archive, low_pdf_quality=args.low_pdf_quality) | 159 | add2archive=args.add2archive, low_pdf_quality=args.low_pdf_quality) |
| 154 | if class_file: | 160 | if class_file: |
| 155 | func(class_file, filename, args.force, args.add2archive) | 161 | ret += func(class_file, filename, args.force, args.add2archive) |
| 156 | else: | 162 | else: |
| 157 | print('Unable to process %s' % filename) | 163 | ret = 1 |
| 164 | print('[-] Unable to process %s' % filename) | ||
| 165 | sys.exit(ret) | ||
| 158 | 166 | ||
| 159 | if __name__ == '__main__': | 167 | if __name__ == '__main__': |
| 160 | main() | 168 | main() |
