Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added opt flags to yangpath.py for --sparse, --config-after, and --prefix-module #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions openconfig_pyang/plugins/yangpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ def add_opts(self, optparser):
action="store_true",
help="""Generate paths output for use with relocate
plugin"""),
optparse.make_option("--prefix-module",
dest="prefix_module",
action="store_true",
help="""Generate paths output with module name
prefix"""),
optparse.make_option("--sparse",
dest="sparse",
action="store_true",
help="""Generate paths output without extra
whitespace"""),
optparse.make_option("--config-after",
dest="config_after",
action="store_true",
help="""Generate paths output with configurable
flag after each path"""),
]
g = optparser.add_option_group("paths output specific options")
g.add_options(optlist)
Expand Down Expand Up @@ -109,7 +124,7 @@ def emit_paths(ctx, modules, fd):
for module in modules:
children = [child for child in module.i_children]
if children:
if (not ctx.opts.print_plain and not ctx.opts.relocate_output):
if (not ctx.opts.print_plain and not ctx.opts.relocate_output and not ctx.opts.prefix_module):
fd.write('\nmodule %s:\n' % module.i_modulename)
elif ctx.opts.relocate_output:
fd.write('\nmodule %s\n' % module.i_modulename)
Expand Down Expand Up @@ -155,7 +170,7 @@ def print_node(node, module, fd, prefix, ctx, level=0):
else:
config = None

pathstr = get_pathstr(pathstr, config, ctx, level)
pathstr = get_pathstr(pathstr, config, ctx, level, module.i_modulename)

fd.write(pathstr)

Expand All @@ -175,19 +190,41 @@ def print_node(node, module, fd, prefix, ctx, level=0):
print_children(node.i_children, module, fd, prefix, ctx, level)


def get_pathstr(pathstr, config, ctx, level):
def get_pathstr(pathstr, config, ctx, level, modname):

if ctx.opts.print_plain or ctx.opts.relocate_output:
return pathstr

s = ''
if ctx.opts.print_depth:
s += ' [%d]' % level
else:
s += ' '
if config:
s += ' [%s] %s' % (config, pathstr)
if ctx.opts.prefix_module:
s += '%s:' % modname
robshakir marked this conversation as resolved.
Show resolved Hide resolved
if ctx.opts.sparse:
if ctx.opts.print_depth:
s += ' [%d]' % level
if ctx.opts.config_after:
if config:
s += ' %s [%s]' % (pathstr, config)
else:
s += ' %s' % (pathstr)
else:
if config:
s += ' [%s] %s' % (config, pathstr)
else:
s += ' %s' % (pathstr)
else:
s += ' %s' % (pathstr)
if ctx.opts.print_depth:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this block become a function that just takes an argument of the indentation to be applied (since it looks like lines 204-208 differ from this block only based on the indentation on line 223 and 228?

s += ' [%d]' % level
else:
s += ' '
if ctx.opts.config_after:
if config:
s += ' %s [%s]' % (pathstr, config)
else:
s += ' %s' % (pathstr)
else:
if config:
s += ' [%s] %s' % (config, pathstr)
else:
s += ' %s' % (pathstr)

return s