1
2
3 import sys
4 from os.path import dirname, basename
5 from glob import glob
6 from importlib import import_module
7
8
9 __all__ = ['available', 'wrapper']
10 current_dir = dirname(__file__)
11 required_objects = ['__meta__', 'main']
12 required_meta = ['from', 'requires', 'to', 'provides']
13
14 available = {}
15 sys.path.insert(0, current_dir)
16 for filename in glob('{}/*.py'.format(current_dir)):
17 worker = basename(filename[:-3])
18 if worker != '__init__':
19 worker_module = import_module(worker)
20 worker_objects = dir(worker_module)
21 for obj in required_objects:
22 if obj not in worker_objects:
23 break
24 else:
25 meta_obj = getattr(worker_module, '__meta__')
26 meta_keys = meta_obj.keys()
27 for meta in required_meta:
28 if meta not in meta_keys:
29 break
30 else:
31 __all__.append(worker)
32 available[worker] = {'main': getattr(worker_module, 'main'),
33 'from': meta_obj['from'],
34 'requires': meta_obj['requires'],
35 'to': meta_obj['to'],
36 'provides': meta_obj['provides'],
37 }
38
40
41
42
43
44
45
46
47
48
49
50
51 worker, document = child_connection.recv()
52 result = available[worker]['main'](document)
53 child_connection.send(result)
54