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

Skip to content

Commit 0a6c176

Browse files
committed
add stevedore
1 parent 5086473 commit 0a6c176

File tree

8 files changed

+189
-0
lines changed

8 files changed

+189
-0
lines changed

test_stevedore/example/example/__init__.py

Whitespace-only changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import textwrap
2+
3+
from example1 import base
4+
5+
6+
class FieldList(base.FormatterBase):
7+
"""Format values as a reStructuredText field list.
8+
9+
For example::
10+
11+
: name1 : value
12+
: name2 : value
13+
: name3 : a long value
14+
will be wrapped with
15+
a hanging indent
16+
"""
17+
18+
def format(self, data):
19+
"""Format the data and return unicode text.
20+
21+
:param data: A dictionary with string keys and simple types as
22+
values.
23+
:type data: dict(str:?)
24+
"""
25+
for name, value in sorted(data.items()):
26+
full_text = ': {name} : {value}'.format(
27+
name=name,
28+
value=value,
29+
)
30+
wrapped_text = textwrap.fill(
31+
full_text,
32+
initial_indent='',
33+
subsequent_indent=' ',
34+
width=self.max_width,
35+
)
36+
yield wrapped_text + '\n'

test_stevedore/example/setup.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# stevedore/example2/setup.py
2+
from setuptools import setup, find_packages
3+
4+
setup(
5+
name='stevedore-example',
6+
version='1.0',
7+
8+
description='Demonstration package for stevedore',
9+
10+
url='http://git.openstack.org/cgit/openstack/stevedore',
11+
12+
classifiers=['Development Status :: 3 - Alpha',
13+
'License :: OSI Approved :: Apache Software License',
14+
'Programming Language :: Python',
15+
'Programming Language :: Python :: 2',
16+
'Programming Language :: Python :: 2.7',
17+
'Programming Language :: Python :: 3',
18+
'Programming Language :: Python :: 3.4',
19+
'Intended Audience :: Developers',
20+
'Environment :: Console',
21+
],
22+
23+
platforms=['Any'],
24+
25+
scripts=[],
26+
27+
provides=['example',
28+
],
29+
30+
packages=find_packages(),
31+
include_package_data=True,
32+
33+
entry_points={
34+
'test_stevedore.study': [
35+
'field =example.example:FieldList',
36+
],
37+
},
38+
39+
zip_safe=False,
40+
)

test_stevedore/example1/example1/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import abc
2+
import six
3+
4+
5+
@six.add_metaclass(abc.ABCMeta)
6+
class FormatterBase(object):
7+
"""Base class for example plugin used in the tutorial.
8+
"""
9+
10+
def __init__(self, max_width=60):
11+
self.max_width = max_width
12+
13+
@abc.abstractmethod
14+
def format(self, data):
15+
pass
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# stevedore/example/load_as_driver.py
2+
from __future__ import print_function
3+
4+
import argparse
5+
6+
from stevedore import driver
7+
8+
9+
if __name__ == '__main__':
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument(
12+
'format',
13+
nargs='?',
14+
default='simple',
15+
help='the output format',
16+
)
17+
parser.add_argument(
18+
'--width',
19+
default=60,
20+
type=int,
21+
help='maximum output width for text',
22+
)
23+
parsed_args = parser.parse_args()
24+
25+
data = {
26+
'a': 'A',
27+
'b': 'B',
28+
'long': 'word ' * 80,
29+
}
30+
31+
mgr = driver.DriverManager(
32+
namespace='test_stevedore.study',
33+
name=parsed_args.format,
34+
invoke_on_load=True,
35+
invoke_args=(parsed_args.width,),
36+
)
37+
for chunk in mgr.driver.format(data):
38+
print(chunk, end='')
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from example1 import base
2+
3+
4+
class Simple(base.FormatterBase):
5+
"""A very basic formatter.
6+
"""
7+
8+
def format(self, data):
9+
"""Format the data and return unicode text.
10+
11+
:param data: A dictionary with string keys and simple types as
12+
values.
13+
:type data: dict(str:?)
14+
"""
15+
for name, value in sorted(data.items()):
16+
line = '{name} = {value}\n'.format(
17+
name=name,
18+
value=value,
19+
)
20+
yield line

test_stevedore/example1/setup.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='stevedore-example1',
5+
version='1.0',
6+
7+
description='Demonstration package for stevedore',
8+
9+
url='http://git.openstack.org/cgit/openstack/stevedore',
10+
11+
classifiers=['Development Status :: 3 - Alpha',
12+
'License :: OSI Approved :: Apache Software License',
13+
'Programming Language :: Python',
14+
'Programming Language :: Python :: 2',
15+
'Programming Language :: Python :: 2.7',
16+
'Programming Language :: Python :: 3',
17+
'Programming Language :: Python :: 3.4',
18+
'Intended Audience :: Developers',
19+
'Environment :: Console',
20+
],
21+
22+
platforms=['Any'],
23+
24+
scripts=[],
25+
26+
provides=['test_stevedore.example1',
27+
],
28+
29+
packages=find_packages(),
30+
include_package_data=True,
31+
32+
entry_points={
33+
'test_stevedore.study': [
34+
'simple = example1.simple:Simple',
35+
'plain = example1.simple:Simple',
36+
],
37+
},
38+
39+
zip_safe=False,
40+
)

0 commit comments

Comments
 (0)