diff options
| author | jvoisin | 2018-04-14 21:23:31 +0200 |
|---|---|---|
| committer | jvoisin | 2018-04-14 21:23:31 +0200 |
| commit | 96299c6a5350f59eab022a09400eddcc347daede (patch) | |
| tree | 492df3a7637b2d1cb45424615ab2777043043eab /main.py | |
| parent | 6f4ed2490fbcde0b74e7b8251ad71e29b430b8ef (diff) | |
Add lightweight processing for PDF
Diffstat (limited to 'main.py')
| -rwxr-xr-x | main.py | 15 |
1 files changed, 10 insertions, 5 deletions
| @@ -31,6 +31,8 @@ def create_arg_parser(): | |||
| 31 | help='list all supported fileformats') | 31 | help='list all supported fileformats') |
| 32 | info.add_argument('-s', '--show', action='store_true', | 32 | info.add_argument('-s', '--show', action='store_true', |
| 33 | help='list all the harmful metadata of a file without removing them') | 33 | help='list all the harmful metadata of a file without removing them') |
| 34 | info.add_argument('-L', '--lightweight', action='store_true', | ||
| 35 | help='remove SOME metadata') | ||
| 34 | return parser | 36 | return parser |
| 35 | 37 | ||
| 36 | 38 | ||
| @@ -50,7 +52,7 @@ def show_meta(filename:str): | |||
| 50 | print(" %s: harmful content" % k) | 52 | print(" %s: harmful content" % k) |
| 51 | 53 | ||
| 52 | 54 | ||
| 53 | def clean_meta(filename:str): | 55 | def clean_meta(filename:str, is_lightweigth:bool): |
| 54 | if not __check_file(filename, os.R_OK|os.W_OK): | 56 | if not __check_file(filename, os.R_OK|os.W_OK): |
| 55 | return | 57 | return |
| 56 | 58 | ||
| @@ -58,7 +60,10 @@ def clean_meta(filename:str): | |||
| 58 | if p is None: | 60 | if p is None: |
| 59 | print("[-] %s's format (%s) is not supported" % (filename, mtype)) | 61 | print("[-] %s's format (%s) is not supported" % (filename, mtype)) |
| 60 | return | 62 | return |
| 61 | p.remove_all() | 63 | if is_lightweigth: |
| 64 | p.remove_all_lightweight() | ||
| 65 | else: | ||
| 66 | p.remove_all() | ||
| 62 | 67 | ||
| 63 | 68 | ||
| 64 | def show_parsers(): | 69 | def show_parsers(): |
| @@ -78,12 +83,12 @@ def __get_files_recursively(files): | |||
| 78 | for _f in _files: | 83 | for _f in _files: |
| 79 | yield os.path.join(path, _f) | 84 | yield os.path.join(path, _f) |
| 80 | 85 | ||
| 81 | def __do_clean_async(q): | 86 | def __do_clean_async(is_lightweigth, q): |
| 82 | while True: | 87 | while True: |
| 83 | f = q.get() | 88 | f = q.get() |
| 84 | if f is None: # nothing more to process | 89 | if f is None: # nothing more to process |
| 85 | return | 90 | return |
| 86 | clean_meta(f) | 91 | clean_meta(is_lightweigth, f) |
| 87 | q.task_done() | 92 | q.task_done() |
| 88 | 93 | ||
| 89 | 94 | ||
| @@ -109,7 +114,7 @@ def main(): | |||
| 109 | q.put(f) | 114 | q.put(f) |
| 110 | 115 | ||
| 111 | for _ in range(multiprocessing.cpu_count()): | 116 | for _ in range(multiprocessing.cpu_count()): |
| 112 | worker = Thread(target=__do_clean_async, args=(q, )) | 117 | worker = Thread(target=__do_clean_async, args=(mode, q)) |
| 113 | worker.start() | 118 | worker.start() |
| 114 | threads.append(worker) | 119 | threads.append(worker) |
| 115 | 120 | ||
