Skip to content

Commit

Permalink
F: 实现基于stevedore的插件实现,并将原expect方法移到hand包中
Browse files Browse the repository at this point in the history
  • Loading branch information
littlemo committed May 1, 2018
1 parent 12b45a8 commit 8e477c8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
29 changes: 29 additions & 0 deletions mohand_plugin_expect/hand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from mohand.hand import HandDict

hand = HandDict()
# print('HandDict@mohand_plugin_expect:', hand)
# print('HandDict@mohand_plugin_expect:', id(hand))


def expect(*dargs, **dkwargs):
def wrapper(func):
@hand._click.command(
name=func.__name__.lower(),
help=func.__doc__)
@hand._click.option(
'--cmd',
default=dkwargs.get('cmd'),
help='用于构造上下文环境的终端命令,将传入 pexpect.spawn')
@hand._click.option(
'--timeout', '-t',
type=hand._click.INT,
default=dkwargs.get('timeout'),
help='expect 的超时时间')
def _wrapper(*args, **kwargs):
print("decrator param:", dargs, dkwargs)
print("function param:", args, kwargs)
kwargs.pop('cmd', None)
kwargs.pop('timeout', None)
return func(*args, **kwargs)
return _wrapper
return wrapper
33 changes: 6 additions & 27 deletions mohand_plugin_expect/main.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
import click
from mohand import hand
from mohand_plugin_expect.hand import expect

from mohand.main import main
from mohand.decrator import register


@register
def expect(*dargs, **dkwargs):
def wrapper(func):
@main.command(
name=func.__name__.lower(),
help=func.__doc__)
@click.option(
'--cmd',
default=dkwargs.get('cmd'),
help='用于构造上下文环境的终端命令,将传入 pexpect.spawn')
@click.option(
'--timeout', '-t',
type=click.INT,
default=dkwargs.get('timeout'),
help='expect 的超时时间')
def _wrapper(*args, **kwargs):
print("decrator param:", dargs, dkwargs)
print("function param:", args, kwargs)
kwargs.pop('cmd', None)
kwargs.pop('timeout', None)
return func(*args, **kwargs)
return _wrapper
return wrapper
class ExpectHand(hand.HandBase):
def register(self):
# print('ExpectHand:', expect)
return expect
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
},
install_requires=open('requirements/pip.txt').read().splitlines(),
entry_points={
'mohand.plugin.hand': [
'expect = mohand_plugin_expect.main:ExpectHand',
],
},
classifiers=[
'Development Status :: 1 - Planning',
Expand Down

0 comments on commit 8e477c8

Please sign in to comment.