From 8dc80f7213f3cd181bd086d1b76c2f53f1690202 Mon Sep 17 00:00:00 2001 From: Kiran Kumar Kotari Date: Sat, 8 Jul 2023 18:00:07 -0400 Subject: [PATCH 1/8] adding --uml-skip-module, --uml-add-legend --- pyang/__init__.py | 2 +- pyang/plugins/uml.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pyang/__init__.py b/pyang/__init__.py index cfee11cf..a418e127 100644 --- a/pyang/__init__.py +++ b/pyang/__init__.py @@ -1,4 +1,4 @@ """The pyang library for parsing, validating, and converting YANG modules""" -__version__ = '2.5.3' +__version__ = '2.5.4' __date__ = '2022-03-30' diff --git a/pyang/plugins/uml.py b/pyang/plugins/uml.py index 547f44fc..f9554571 100644 --- a/pyang/plugins/uml.py +++ b/pyang/plugins/uml.py @@ -93,6 +93,16 @@ def add_opts(self, optparser): optparse.make_option("--uml-filter-file", dest="uml_filter_file", help="NOT IMPLEMENTED: Only paths in the filter file will be included in the diagram"), + optparse.make_option("--uml-skip-module", + dest="uml_skip_module", + action="append", + default=[], + metavar="SKIP MODULE", + help="skips given modules, i.e., --uml-skip-module=tailf-ncs"), + optparse.make_option("--uml-add-legend", + dest="uml_add_legend", + action="store_true", + help="Adds legend about grouping yang file in the UML"), ] if hasattr(optparser, 'uml_opts'): g = optparser.uml_opts @@ -166,6 +176,7 @@ class uml_emitter: _ctx = None post_strings = [] module_prefixes = [] + ctx_grp_files = set() def __init__(self, ctx): self._ctx = ctx @@ -188,6 +199,8 @@ def __init__(self, ctx): self.ctx_title = ctx.opts.uml_title self.ctx_inline_augments = ctx.opts.uml_inline_augments + self.ctx_skip_module = set(ctx.opts.uml_skip_module) + self.ctx_add_legend = ctx.opts.uml_add_legend no = ctx.opts.uml_no.split(",") self.ctx_leafrefs = not "leafref" in no @@ -255,6 +268,10 @@ def emit(self, modules, fd): if not self.ctx_filterfile: self.post_process_module(module, fd) + + if self.ctx_add_legend: + self.emit_uml_legend(module, fd) + if not self.ctx_filterfile: self.post_process_diagram(fd) @@ -413,7 +430,14 @@ def emit_child_stmt(self, parent, node, fd, cont = True): if hasattr(node, 'i_grouping') and (self._ctx.opts.uml_inline) and cont: grouping_node = node.i_grouping if grouping_node is not None: + # skip grouping modules if given + module = str(grouping_node.main_module()).split()[-1] + if module in self.ctx_skip_module: + fd.write('%s : %s {uses} \n' %(self.full_path(parent), node.arg)) + return # inline grouping here + # collecting grouping module file names + self.ctx_grp_files.add(str(grouping_node.pos).split(':')[0].split('/')[-1]) # sys.stderr.write('Found target grouping to inline %s %s \n' %(grouping_node.keyword, grouping_node.arg)) for children in grouping_node.substmts: # make the inlined parent to parent rather then the grouping to make full path unique @@ -591,7 +615,12 @@ def emit_module_header(self, module, fd): def emit_module_class(self, module, fd): fd.write('class \"%s\" as %s << (M, #33CCFF) module>> \n' %(self.full_display_path(module), self.full_path(module))) - + def emit_uml_legend(self, module, fd): + fd.write('legend \n') + fd.write('Grouping data pulled from \n') + for file in self.ctx_grp_files: + fd.write(f' {file} \n') + fd.write('endlegend \n') def emit_uml_footer(self, module, fd): if self._ctx.opts.uml_footer is not None: From a58f29773e5f33bb7ee1aa2ba08feb6175c77602 Mon Sep 17 00:00:00 2001 From: Kiran Kumar Kotari Date: Mon, 10 Jul 2023 16:38:31 -0400 Subject: [PATCH 2/8] Update pyang/plugins/uml.py updating `--uml-add-legend` help Co-authored-by: Nick Hancock --- pyang/plugins/uml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyang/plugins/uml.py b/pyang/plugins/uml.py index f9554571..daa52b28 100644 --- a/pyang/plugins/uml.py +++ b/pyang/plugins/uml.py @@ -102,7 +102,7 @@ def add_opts(self, optparser): optparse.make_option("--uml-add-legend", dest="uml_add_legend", action="store_true", - help="Adds legend about grouping yang file in the UML"), + help="Adds a legend specifying in which modules the groupings referenced in the diagram are to be found"), ] if hasattr(optparser, 'uml_opts'): g = optparser.uml_opts From ae249d6c92714dd6aa87d67e1603970f88c40fb5 Mon Sep 17 00:00:00 2001 From: Kiran Kumar Kotari Date: Mon, 10 Jul 2023 16:40:09 -0400 Subject: [PATCH 3/8] Update pyang/plugins/uml.py updating to module Co-authored-by: Nick Hancock --- pyang/plugins/uml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyang/plugins/uml.py b/pyang/plugins/uml.py index daa52b28..17a55b9d 100644 --- a/pyang/plugins/uml.py +++ b/pyang/plugins/uml.py @@ -437,7 +437,7 @@ def emit_child_stmt(self, parent, node, fd, cont = True): return # inline grouping here # collecting grouping module file names - self.ctx_grp_files.add(str(grouping_node.pos).split(':')[0].split('/')[-1]) + self.ctx_grp_files.add(module) # sys.stderr.write('Found target grouping to inline %s %s \n' %(grouping_node.keyword, grouping_node.arg)) for children in grouping_node.substmts: # make the inlined parent to parent rather then the grouping to make full path unique From 23f5bc4fd4468b920ed44889ea98f5889a96edac Mon Sep 17 00:00:00 2001 From: Kiran Kumar Kotari Date: Mon, 10 Jul 2023 16:40:40 -0400 Subject: [PATCH 4/8] Update pyang/plugins/uml.py legend msg update Co-authored-by: Nick Hancock --- pyang/plugins/uml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyang/plugins/uml.py b/pyang/plugins/uml.py index 17a55b9d..ec8f14dd 100644 --- a/pyang/plugins/uml.py +++ b/pyang/plugins/uml.py @@ -617,7 +617,7 @@ def emit_module_class(self, module, fd): def emit_uml_legend(self, module, fd): fd.write('legend \n') - fd.write('Grouping data pulled from \n') + fd.write('Referenced groupings to be found in the following modules:' \n') for file in self.ctx_grp_files: fd.write(f' {file} \n') fd.write('endlegend \n') From 0d27a447c652040353a6ff2c843507d161b42b40 Mon Sep 17 00:00:00 2001 From: Kiran Kumar Kotari Date: Mon, 10 Jul 2023 20:51:38 -0400 Subject: [PATCH 5/8] opt reformated --- pyang/__init__.py | 2 +- pyang/plugins/uml.py | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pyang/__init__.py b/pyang/__init__.py index a418e127..cfee11cf 100644 --- a/pyang/__init__.py +++ b/pyang/__init__.py @@ -1,4 +1,4 @@ """The pyang library for parsing, validating, and converting YANG modules""" -__version__ = '2.5.4' +__version__ = '2.5.3' __date__ = '2022-03-30' diff --git a/pyang/plugins/uml.py b/pyang/plugins/uml.py index ec8f14dd..4814bf27 100644 --- a/pyang/plugins/uml.py +++ b/pyang/plugins/uml.py @@ -93,12 +93,11 @@ def add_opts(self, optparser): optparse.make_option("--uml-filter-file", dest="uml_filter_file", help="NOT IMPLEMENTED: Only paths in the filter file will be included in the diagram"), - optparse.make_option("--uml-skip-module", - dest="uml_skip_module", + optparse.make_option("--uml-no-inline-groupings-from", + dest="uml_no_inline_groupings_from", action="append", default=[], - metavar="SKIP MODULE", - help="skips given modules, i.e., --uml-skip-module=tailf-ncs"), + help="Skips given modules from inline augmentation"), optparse.make_option("--uml-add-legend", dest="uml_add_legend", action="store_true", @@ -199,7 +198,7 @@ def __init__(self, ctx): self.ctx_title = ctx.opts.uml_title self.ctx_inline_augments = ctx.opts.uml_inline_augments - self.ctx_skip_module = set(ctx.opts.uml_skip_module) + self.ctx_no_inline_groupings_from = set(ctx.opts.uml_no_inline_groupings_from) self.ctx_add_legend = ctx.opts.uml_add_legend no = ctx.opts.uml_no.split(",") @@ -432,7 +431,7 @@ def emit_child_stmt(self, parent, node, fd, cont = True): if grouping_node is not None: # skip grouping modules if given module = str(grouping_node.main_module()).split()[-1] - if module in self.ctx_skip_module: + if module in self.ctx_no_inline_groupings_from: fd.write('%s : %s {uses} \n' %(self.full_path(parent), node.arg)) return # inline grouping here From d98c82b9016de54f4bec6e0adc5614d3d6f004b4 Mon Sep 17 00:00:00 2001 From: Kiran Kumar Kotari Date: Mon, 10 Jul 2023 21:05:02 -0400 Subject: [PATCH 6/8] pull out legend --- pyang/plugins/uml.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/pyang/plugins/uml.py b/pyang/plugins/uml.py index 4814bf27..e88f08fe 100644 --- a/pyang/plugins/uml.py +++ b/pyang/plugins/uml.py @@ -98,10 +98,6 @@ def add_opts(self, optparser): action="append", default=[], help="Skips given modules from inline augmentation"), - optparse.make_option("--uml-add-legend", - dest="uml_add_legend", - action="store_true", - help="Adds a legend specifying in which modules the groupings referenced in the diagram are to be found"), ] if hasattr(optparser, 'uml_opts'): g = optparser.uml_opts @@ -175,7 +171,6 @@ class uml_emitter: _ctx = None post_strings = [] module_prefixes = [] - ctx_grp_files = set() def __init__(self, ctx): self._ctx = ctx @@ -199,7 +194,6 @@ def __init__(self, ctx): self.ctx_inline_augments = ctx.opts.uml_inline_augments self.ctx_no_inline_groupings_from = set(ctx.opts.uml_no_inline_groupings_from) - self.ctx_add_legend = ctx.opts.uml_add_legend no = ctx.opts.uml_no.split(",") self.ctx_leafrefs = not "leafref" in no @@ -268,9 +262,6 @@ def emit(self, modules, fd): if not self.ctx_filterfile: self.post_process_module(module, fd) - if self.ctx_add_legend: - self.emit_uml_legend(module, fd) - if not self.ctx_filterfile: self.post_process_diagram(fd) @@ -435,8 +426,6 @@ def emit_child_stmt(self, parent, node, fd, cont = True): fd.write('%s : %s {uses} \n' %(self.full_path(parent), node.arg)) return # inline grouping here - # collecting grouping module file names - self.ctx_grp_files.add(module) # sys.stderr.write('Found target grouping to inline %s %s \n' %(grouping_node.keyword, grouping_node.arg)) for children in grouping_node.substmts: # make the inlined parent to parent rather then the grouping to make full path unique @@ -614,13 +603,6 @@ def emit_module_header(self, module, fd): def emit_module_class(self, module, fd): fd.write('class \"%s\" as %s << (M, #33CCFF) module>> \n' %(self.full_display_path(module), self.full_path(module))) - def emit_uml_legend(self, module, fd): - fd.write('legend \n') - fd.write('Referenced groupings to be found in the following modules:' \n') - for file in self.ctx_grp_files: - fd.write(f' {file} \n') - fd.write('endlegend \n') - def emit_uml_footer(self, module, fd): if self._ctx.opts.uml_footer is not None: fd.write('center footer\n %s \n endfooter \n' %self._ctx.opts.uml_footer) From 1e731202a7eabc519a879b82c945e8979dd9e40d Mon Sep 17 00:00:00 2001 From: Kiran Kumar Kotari Date: Tue, 11 Jul 2023 18:02:42 -0400 Subject: [PATCH 7/8] mobing options to right place --- pyang/plugins/uml.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyang/plugins/uml.py b/pyang/plugins/uml.py index e88f08fe..ea637109 100644 --- a/pyang/plugins/uml.py +++ b/pyang/plugins/uml.py @@ -62,6 +62,11 @@ def add_opts(self, optparser): dest="uml_inline", default =False, help="Inline groupings where they are used."), + optparse.make_option("--uml-no-inline-groupings-from", + dest="uml_no_inline_groupings_from", + action="append", + default=[], + help="Skips given modules from inline groupings i.e., --uml-inline-groupings"), optparse.make_option("--uml-inline-augments", action="store_true", dest="uml_inline_augments", @@ -93,11 +98,6 @@ def add_opts(self, optparser): optparse.make_option("--uml-filter-file", dest="uml_filter_file", help="NOT IMPLEMENTED: Only paths in the filter file will be included in the diagram"), - optparse.make_option("--uml-no-inline-groupings-from", - dest="uml_no_inline_groupings_from", - action="append", - default=[], - help="Skips given modules from inline augmentation"), ] if hasattr(optparser, 'uml_opts'): g = optparser.uml_opts From 1e5e94d72bcf667205b4923ec1a380806ea5e8c8 Mon Sep 17 00:00:00 2001 From: Kiran Kumar Kotari Date: Tue, 11 Jul 2023 18:15:17 -0400 Subject: [PATCH 8/8] uml options update --- pyang/plugins/uml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyang/plugins/uml.py b/pyang/plugins/uml.py index ea637109..7399689e 100644 --- a/pyang/plugins/uml.py +++ b/pyang/plugins/uml.py @@ -66,7 +66,7 @@ def add_opts(self, optparser): dest="uml_no_inline_groupings_from", action="append", default=[], - help="Skips given modules from inline groupings i.e., --uml-inline-groupings"), + help="Skips given modules from inline groupings. \nExample --uml-no-inline-groupings-from=ietf-yang-push"), optparse.make_option("--uml-inline-augments", action="store_true", dest="uml_inline_augments",