Commit 7830d224 authored by Peter V. Saveliev's avatar Peter V. Saveliev

cli: support report filter chains / pipes

parent 8a4793e0
......@@ -2,6 +2,7 @@
t_stmt = 1
t_dict = 2
t_comma = 3
t_pipe = 4
t_end_of_dict = 7
t_end_of_sentence = 8
t_end_of_stream = 9
......
......@@ -3,6 +3,7 @@ import shlex
from pyroute2.common import basestring
from pyroute2.cli import (t_stmt,
t_dict,
t_pipe,
t_comma,
t_end_of_dict,
t_end_of_sentence,
......@@ -95,6 +96,12 @@ class Token(object):
elif first == ',':
self.kind = t_comma
##
# pipe
#
elif first == '|':
self.kind = t_pipe
##
# simple statement
#
......
......@@ -5,6 +5,7 @@ from collections import namedtuple
from pyroute2.common import basestring
from pyroute2.cli import t_dict
from pyroute2.cli import t_stmt
from pyroute2.cli import t_pipe
from pyroute2.cli.parser import Parser
......@@ -72,11 +73,46 @@ class Session(object):
'argv',
'kwarg'))(t_dict, [], {}))
if nt.kind != t_dict:
raise TypeError('function arguments expected')
if nt.kind not in (t_dict, t_pipe):
raise TypeError('function arguments or pipe expected')
if nt.kind == t_dict:
args = nt
try:
pipe = next(token)
if pipe.kind != t_pipe:
raise TypeError('pipe expected')
except StopIteration:
pipe = None
else:
args = (namedtuple('Token',
('kind',
'argv',
'kwarg'))(t_dict, [], {}))
pipe = nt
# at this step we have
# args -- arguments
# pipe -- pipe or None
try:
ret = obj(*nt.argv, **nt.kwarg)
ret = obj(*args.argv, **args.kwarg)
#
if pipe is not None:
ptr = self.ptr
self.ptr = ret
try:
stmt = next(token)
except StopIteration:
raise TypeError('statement expected')
if stmt.kind != t_stmt:
raise TypeError('statement expected')
try:
self.handle_statement(stmt, token)
except Exception:
pass
self.ptr = ptr
return
if hasattr(obj, '__cli_cptr__'):
obj = ret
elif hasattr(obj, '__cli_publish__'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment