Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3da30e7

Browse files
committed
add stevedore extension
1 parent 0a6c176 commit 3da30e7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# stevedore/example/load_as_extension.py
2+
from __future__ import print_function
3+
4+
import argparse
5+
6+
from stevedore import extension
7+
8+
9+
if __name__ == '__main__':
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument(
12+
'--width',
13+
default=60,
14+
type=int,
15+
help='maximum output width for text',
16+
)
17+
parsed_args = parser.parse_args()
18+
19+
data = {
20+
'a': 'A',
21+
'b': 'B',
22+
'long': 'word ' * 80,
23+
}
24+
25+
mgr = extension.ExtensionManager(
26+
namespace='test_stevedore.study',
27+
invoke_on_load=True,
28+
invoke_args=(parsed_args.width,),
29+
)
30+
31+
def format_data(ext, data):
32+
return (ext.name, ext.obj.format(data))
33+
34+
results = mgr.map(format_data, data)
35+
36+
for name, result in results:
37+
print('Formatter: {0}'.format(name))
38+
for chunk in result:
39+
print(chunk, end='')
40+
print('')

0 commit comments

Comments
 (0)