stevedore/stevedore/example/load_as_driver.py
Doug Hellmann 48c8393c5e Add example of loading as a driver
Create an example program to load the formatters
from the tutorial as a driver and print some data.

Update run_sphinx to watch .txt files.

Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
2013-06-05 18:02:12 -04:00

38 lines
802 B
Python

from __future__ import print_function
import argparse
from stevedore import driver
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'format',
nargs='?',
default='simple',
help='the output format',
)
parser.add_argument(
'--width',
default=60,
type=int,
help='maximum output width for text',
)
parsed_args = parser.parse_args()
data = {
'a': 'A',
'b': 'B',
'long': 'word ' * 80,
}
mgr = driver.DriverManager(
namespace='stevedore.example.formatter',
name=parsed_args.format,
invoke_on_load=True,
invoke_args=(parsed_args.width,),
)
for chunk in mgr.driver.format(data):
print(chunk, end='')