diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2022-10-04 13:30:04 +0200 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2022-10-06 15:34:32 +0200 |
commit | 9eebf97e3d3fe8bff0d3c5ecdae39f15bd93f40b (patch) | |
tree | 04b57dbd4183fd0f0b415a022e12cb72e29fdf16 /python | |
parent | lib: remove unused CLI macros (diff) | |
download | frr-9eebf97e3d3fe8bff0d3c5ecdae39f15bd93f40b.tar.xz frr-9eebf97e3d3fe8bff0d3c5ecdae39f15bd93f40b.zip |
lib: make cmd_element->attr a bitmask & clarify
It already "looks" like a bitmask, but we currently can't flag a command
both YANG and HIDDEN at the same time. It really should be a bitmask.
Also clarify DEPRECATED behaviour (or the absence thereof.)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/clippy/__init__.py | 22 | ||||
-rw-r--r-- | python/xrelfo.py | 14 |
2 files changed, 29 insertions, 7 deletions
diff --git a/python/clippy/__init__.py b/python/clippy/__init__.py index 344a1c91e..c356a29d3 100644 --- a/python/clippy/__init__.py +++ b/python/clippy/__init__.py @@ -17,8 +17,22 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os, stat + +try: + from enum import IntFlag as _IntFlag +except ImportError: + # python <3.6 + from enum import IntEnum as _IntFlag # type: ignore + import _clippy -from _clippy import parse, Graph, GraphNode +from _clippy import ( + parse, + Graph, + GraphNode, + CMD_ATTR_YANG, + CMD_ATTR_HIDDEN, + CMD_ATTR_DEPRECATED, +) frr_top_src = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -78,3 +92,9 @@ def wrdiff(filename, buf, reffiles=[]): with open(newname, "w") as out: out.write(buf) os.rename(newname, filename) + + +class CmdAttr(_IntFlag): + YANG = CMD_ATTR_YANG + HIDDEN = CMD_ATTR_HIDDEN + DEPRECATED = CMD_ATTR_DEPRECATED diff --git a/python/xrelfo.py b/python/xrelfo.py index 17262da8d..3bfe9950d 100644 --- a/python/xrelfo.py +++ b/python/xrelfo.py @@ -26,7 +26,7 @@ import argparse from clippy.uidhash import uidhash from clippy.elf import * -from clippy import frr_top_src +from clippy import frr_top_src, CmdAttr from tiabwarfo import FieldApplicator try: @@ -196,8 +196,6 @@ Xref.containers[XREFT_LOGMSG] = XrefLogmsg class CmdElement(ELFDissectStruct, XrelfoJson): struct = 'cmd_element' - cmd_attrs = { 0: None, 1: 'deprecated', 2: 'hidden'} - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -207,10 +205,14 @@ class CmdElement(ELFDissectStruct, XrelfoJson): jsobj.update({ 'string': self.string, 'doc': self.doc, - 'attr': self.cmd_attrs.get(self.attr, self.attr), }) - if jsobj['attr'] is None: - del jsobj['attr'] + if self.attr: + jsobj['attr'] = attr = self.attr + for attrname in CmdAttr.__members__: + val = CmdAttr[attrname] + if attr & val: + jsobj.setdefault('attrs', []).append(attrname.lower()) + attr &= ~val jsobj['defun'] = dict([(i, getattr(self.xref, i)) for i in ['file', 'line', 'func']]) |