diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/clippy/__init__.py | 24 | ||||
| -rw-r--r-- | python/makefile.py | 3 | ||||
| -rw-r--r-- | python/xrelfo.py | 29 |
3 files changed, 46 insertions, 10 deletions
diff --git a/python/clippy/__init__.py b/python/clippy/__init__.py index 344a1c91ee..281e2bb3c6 100644 --- a/python/clippy/__init__.py +++ b/python/clippy/__init__.py @@ -17,8 +17,23 @@ # 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, + CMD_ATTR_NOSH, +) frr_top_src = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -78,3 +93,10 @@ 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 + NOSH = CMD_ATTR_NOSH diff --git a/python/makefile.py b/python/makefile.py index afc993b5b9..bd897b7508 100644 --- a/python/makefile.py +++ b/python/makefile.py @@ -160,6 +160,9 @@ for clippy_file in clippy_scan: # combine daemon .xref files into frr.xref out_lines.append("") +xref_targets = [ + target for target in xref_targets if target not in ["tools/ssd", "vtysh/vtysh"] +] out_lines.append( "xrefs = %s" % (" ".join(["%s.xref" % target for target in xref_targets])) ) diff --git a/python/xrelfo.py b/python/xrelfo.py index 17262da8d9..09455ea9b4 100644 --- a/python/xrelfo.py +++ b/python/xrelfo.py @@ -21,12 +21,21 @@ import os import struct import re import traceback -import json + +json_dump_args = {} + +try: + import ujson as json + + json_dump_args["escape_forward_slashes"] = False +except ImportError: + import json + 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 +205,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 +214,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']]) @@ -416,12 +427,12 @@ def _main(args): if args.output: with open(args.output + '.tmp', 'w') as fd: - json.dump(out, fd, indent=2, sort_keys=True) + json.dump(out, fd, indent=2, sort_keys=True, **json_dump_args) os.rename(args.output + '.tmp', args.output) if args.out_by_file: with open(args.out_by_file + '.tmp', 'w') as fd: - json.dump(outbyfile, fd, indent=2, sort_keys=True) + json.dump(outbyfile, fd, indent=2, sort_keys=True, **json_dump_args) os.rename(args.out_by_file + '.tmp', args.out_by_file) if __name__ == '__main__': |
