Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
6d3323d1
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6d3323d1
编写于
10月 28, 2015
作者:
L
Lukáš Doktor
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #852 from clebergnu/plugins_remove_external
Plugins: remove external plugin support
上级
74dbfb8a
7b969527
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
7 addition
and
123 deletion
+7
-123
avocado/core/app.py
avocado/core/app.py
+4
-7
avocado/core/parser.py
avocado/core/parser.py
+0
-3
avocado/core/plugins/manager.py
avocado/core/plugins/manager.py
+2
-42
docs/source/Plugins.rst
docs/source/Plugins.rst
+0
-27
man/avocado.rst
man/avocado.rst
+1
-2
selftests/functional/test_basic.py
selftests/functional/test_basic.py
+0
-42
未找到文件。
avocado/core/app.py
浏览文件 @
6d3323d1
...
...
@@ -29,17 +29,16 @@ class AvocadoApp(object):
Avocado application.
"""
def
__init__
(
self
,
external_plugins
=
None
):
def
__init__
(
self
):
# Catch all libc runtime errors to STDERR
os
.
environ
[
'LIBC_FATAL_STDERR_'
]
=
'1'
configure
()
self
.
external_plugins
=
external_plugins
self
.
plugin_manager
=
None
self
.
parser
=
Parser
()
self
.
parser
.
start
()
self
.
load_plugin_manager
(
self
.
parser
.
args
.
plugins_dir
)
self
.
load_plugin_manager
()
self
.
ready
=
True
try
:
self
.
parser
.
resume
()
...
...
@@ -48,15 +47,13 @@ class AvocadoApp(object):
except
IOError
:
self
.
ready
=
False
def
load_plugin_manager
(
self
,
plugins_dir
):
def
load_plugin_manager
(
self
):
"""Load Plugin Manager.
:param plugins_dir: Extra plugins directory.
"""
self
.
plugin_manager
=
get_plugin_manager
()
self
.
plugin_manager
.
load_plugins
(
plugins_dir
)
if
self
.
external_plugins
:
self
.
plugin_manager
.
add_plugins
(
self
.
external_plugins
)
self
.
plugin_manager
.
load_plugins
()
self
.
plugin_manager
.
configure
(
self
.
parser
)
def
run
(
self
):
...
...
avocado/core/parser.py
浏览文件 @
6d3323d1
...
...
@@ -43,9 +43,6 @@ class Parser(object):
description
=
DESCRIPTION
)
self
.
application
.
add_argument
(
'-v'
,
'--version'
,
action
=
'version'
,
version
=
'Avocado %s'
%
VERSION
)
self
.
application
.
add_argument
(
'--plugins'
,
action
=
'store'
,
help
=
'Load extra plugins from directory'
,
dest
=
'plugins_dir'
,
default
=
''
)
self
.
application
.
add_argument
(
'--config'
,
metavar
=
'CONFIG_FILE'
,
help
=
'Use custom configuration from a file'
)
...
...
avocado/core/plugins/manager.py
浏览文件 @
6d3323d1
...
...
@@ -17,7 +17,6 @@
import
logging
from
.builtin
import
load_builtins
from
.plugin
import
Plugin
DefaultPluginManager
=
None
...
...
@@ -80,44 +79,7 @@ class BuiltinPluginManager(PluginManager):
name
,
err
)
class
ExternalPluginManager
(
PluginManager
):
"""
Load external plugins.
"""
def
load_plugins
(
self
,
path
,
pattern
=
'avocado_*.py'
):
from
glob
import
glob
import
os
import
imp
plugins
=
[]
if
path
:
candidates
=
glob
(
os
.
path
.
join
(
path
,
pattern
))
candidates
=
[(
os
.
path
.
splitext
(
os
.
path
.
basename
(
x
))[
0
],
path
)
for
x
in
candidates
]
candidates
=
[(
x
[
0
],
imp
.
find_module
(
x
[
0
],
[
path
]))
for
x
in
candidates
]
for
candidate
in
candidates
:
try
:
mod
=
imp
.
load_module
(
candidate
[
0
],
*
candidate
[
1
])
except
Exception
as
err
:
log
.
error
(
"Could not load module plugin '%s': %s"
,
candidate
[
0
],
err
)
else
:
any_plugin
=
False
for
name
in
mod
.
__dict__
:
x
=
getattr
(
mod
,
name
)
if
isinstance
(
x
,
type
)
and
issubclass
(
x
,
Plugin
):
plugins
.
append
(
x
)
any_plugin
=
True
if
not
any_plugin
:
log
.
error
(
"Could not find any plugin in module '%s'"
,
candidate
[
0
])
for
plugin
in
sorted
(
plugins
,
key
=
lambda
plugin
:
plugin
.
priority
):
self
.
add_plugin
(
plugin
())
class
AvocadoPluginManager
(
BuiltinPluginManager
,
ExternalPluginManager
):
class
AvocadoPluginManager
(
BuiltinPluginManager
):
"""
Avocado Plugin Manager.
...
...
@@ -127,11 +89,9 @@ class AvocadoPluginManager(BuiltinPluginManager, ExternalPluginManager):
def
__init__
(
self
):
BuiltinPluginManager
.
__init__
(
self
)
ExternalPluginManager
.
__init__
(
self
)
def
load_plugins
(
self
,
path
=
None
):
def
load_plugins
(
self
):
BuiltinPluginManager
.
load_plugins
(
self
)
ExternalPluginManager
.
load_plugins
(
self
,
path
)
def
get_plugin_manager
():
...
...
docs/source/Plugins.rst
浏览文件 @
6d3323d1
...
...
@@ -91,33 +91,6 @@ point. In this code example it will simply print the plugin's docstring.
:func:`activate <avocado.core.plugins.plugin.Plugin.activate>`, if necessary,
will activate your plugin, overriding Avocado core functionality.
Make Avocado aware of the new plugin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Avocado command line tool has a ``--plugins`` option that allows you to
provide a filesystem location that contains plugins that will be automatically
loaded.
Note that all external plugin files must be prefixed with the ``avocado_`` name,
otherwise it will not be loaded.
In the Avocado source tree, the ``avocado_hello.py`` example is available under
``examples/plugins``. So, in order to enable the hello plugin, you can do a::
$ avocado --plugins examples/plugins/ plugins
Plugins enabled:
...
hello_world - The classical Hello World! plugin example.
...
Run it
~~~~~~
To run the newly created plugin, you can simply call the Avocado command line
tool with newly registered runner command ``hello``::
$ avocado --plugins examples/plugins/ hello
The classical Hello World! plugin example.
Wrap Up
~~~~~~~
...
...
man/avocado.rst
浏览文件 @
6d3323d1
...
...
@@ -6,7 +6,7 @@
SYNOPSIS
========
avocado [-h] [-v] [--
plugins PLUGINS_DIR] [--
config CONFIG_FILE]
avocado [-h] [-v] [--config CONFIG_FILE]
{run,list,sysinfo,multiplex,plugins,datadir} ...
DESCRIPTION
...
...
@@ -30,7 +30,6 @@ on them being loaded::
-h, --help show this help message and exit
-v, --version show program's version number and exit
--plugins PLUGINS_DIR Load extra plugins from directory
--config CONFIG_FILE Use custom configuration from a file
Real use of avocado depends on running avocado subcommands. This a typical list
...
...
selftests/functional/test_basic.py
浏览文件 @
6d3323d1
...
...
@@ -463,48 +463,6 @@ class ExternalRunnerTest(unittest.TestCase):
shutil
.
rmtree
(
self
.
tmpdir
)
class
ExternalPluginsTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
base_sourcedir
=
tempfile
.
mkdtemp
(
prefix
=
'avocado_'
+
__name__
)
self
.
tmpdir
=
tempfile
.
mkdtemp
(
prefix
=
'avocado_'
+
__name__
)
def
test_void_plugin
(
self
):
self
.
void_plugin
=
script
.
make_script
(
os
.
path
.
join
(
self
.
base_sourcedir
,
'avocado_void.py'
),
VOID_PLUGIN_CONTENTS
)
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado --plugins %s plugins'
%
self
.
base_sourcedir
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_output
=
'noname'
self
.
assertIn
(
expected_output
,
result
.
stdout
)
def
test_syntax_error_plugin
(
self
):
self
.
syntax_err_plugin
=
script
.
make_script
(
os
.
path
.
join
(
self
.
base_sourcedir
,
'avocado_syntax_err.py'
),
SYNTAX_ERROR_PLUGIN_CONTENTS
)
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado --plugins %s'
%
self
.
base_sourcedir
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_output
=
'invalid syntax'
self
.
assertIn
(
expected_output
,
result
.
stderr
)
def
test_hello_plugin
(
self
):
self
.
hello_plugin
=
script
.
make_script
(
os
.
path
.
join
(
self
.
base_sourcedir
,
'avocado_hello.py'
),
HELLO_PLUGIN_CONTENTS
)
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado --plugins %s hello'
%
self
.
base_sourcedir
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_output
=
'Hello World!'
self
.
assertIn
(
expected_output
,
result
.
stdout
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
tmpdir
)
if
os
.
path
.
isdir
(
self
.
base_sourcedir
):
shutil
.
rmtree
(
self
.
base_sourcedir
,
ignore_errors
=
True
)
class
AbsPluginsTest
(
object
):
def
setUp
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录