| 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | # Copyright 2018-2026 Mike Fährmann |
| 4 | # |
| 5 | # This program is free software; you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License version 2 as |
| 7 | # published by the Free Software Foundation. |
| 8 | |
| 9 | """Post-processing modules""" |
| 10 | |
| 11 | modules = { |
| 12 | "actions", |
| 13 | "classify", |
| 14 | "compare", |
| 15 | "directory", |
| 16 | "exec", |
| 17 | "hash", |
| 18 | "metadata", |
| 19 | "mtime", |
| 20 | "python", |
| 21 | "rename", |
| 22 | "ugoira", |
| 23 | "zip", |
| 24 | } |
| 25 | |
| 26 | |
| 27 | def find(name): |
| 28 | """Return a postprocessor class with the given name""" |
| 29 | try: |
| 30 | return _cache[name] |
| 31 | except KeyError: |
| 32 | pass |
| 33 | |
| 34 | cls = None |
| 35 | if name in modules: # prevent unwanted imports |
| 36 | try: |
| 37 | module = __import__(name, globals(), None, None, 1) |
| 38 | except ImportError: |
| 39 | pass |
| 40 | else: |
| 41 | cls = module.__postprocessor__ |
| 42 | _cache[name] = cls |
| 43 | return cls |
| 44 | |
| 45 | |
| 46 | # -------------------------------------------------------------------- |
| 47 | # internals |
| 48 | |
| 49 | _cache = {} |