summaryrefslogtreecommitdiffstats
path: root/scripts/contrib/graph-tool
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.microsoft.com>2020-06-14 21:48:42 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-06-16 23:39:28 +0100
commit8f7c45c183e3d9ec15feb507cd923dea85b34f47 (patch)
treeb5f8eef7ade749d665390880ac944a980d159df0 /scripts/contrib/graph-tool
parent5d1e4b1c55ad05620a1c18782beb7cceccd38a0c (diff)
downloadpoky-8f7c45c183e3d9ec15feb507cd923dea85b34f47.tar.gz
poky-8f7c45c183e3d9ec15feb507cd923dea85b34f47.tar.bz2
poky-8f7c45c183e3d9ec15feb507cd923dea85b34f47.zip
graph-tool: switch to argparse
argparse makes this a lot easier to extend. (From OE-Core rev: c751ef8fdc111d1c967029cea7a3ed0f88ce851b) Signed-off-by: Paul Eggleton <paul.eggleton@linux.microsoft.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/contrib/graph-tool')
-rwxr-xr-xscripts/contrib/graph-tool59
1 files changed, 27 insertions, 32 deletions
diff --git a/scripts/contrib/graph-tool b/scripts/contrib/graph-tool
index 6d2e68b82e..9402e617e9 100755
--- a/scripts/contrib/graph-tool
+++ b/scripts/contrib/graph-tool
@@ -11,6 +11,13 @@
#
import sys
+import os
+import argparse
+
+scripts_lib_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'lib'))
+sys.path.insert(0, scripts_lib_path)
+import argparse_oe
+
def get_path_networkx(dotfile, fromnode, tonode):
try:
@@ -34,47 +41,35 @@ def get_path_networkx(dotfile, fromnode, tonode):
return networkx.all_simple_paths(graph, source=fromnode, target=tonode)
-def find_paths(args, usage):
- if len(args) < 3:
- usage()
- sys.exit(1)
-
- fromnode = args[1]
- tonode = args[2]
-
+def find_paths(args):
path = None
- for path in get_path_networkx(args[0], fromnode, tonode):
+ for path in get_path_networkx(args.dotfile, args.fromnode, args.tonode):
print(" -> ".join(map(str, path)))
if not path:
- print("ERROR: no path from %s to %s in graph" % (fromnode, tonode))
- sys.exit(1)
+ print("ERROR: no path from %s to %s in graph" % (args.fromnode, args.tonode))
+ return 1
+
def main():
- import optparse
- parser = optparse.OptionParser(
- usage = '''%prog [options] <command> <arguments>
+ parser = argparse_oe.ArgumentParser(description='Small utility for working with .dot graph files')
-Available commands:
- find-paths <dotfile> <from> <to>
- Find all of the paths between two nodes in a dot graph''')
+ subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
+ subparsers.required = True
- #parser.add_option("-d", "--debug",
- # help = "Report all SRCREV values, not just ones where AUTOREV has been used",
- # action="store_true", dest="debug", default=False)
+ parser_find_paths = subparsers.add_parser('find-paths',
+ help='Find all of the paths between two nodes in a dot graph',
+ description='Finds all of the paths between two nodes in a dot graph')
+ parser_find_paths.add_argument('dotfile', help='.dot graph to search in')
+ parser_find_paths.add_argument('fromnode', help='starting node name')
+ parser_find_paths.add_argument('tonode', help='ending node name')
+ parser_find_paths.set_defaults(func=find_paths)
- options, args = parser.parse_args(sys.argv)
- args = args[1:]
+ args = parser.parse_args()
- if len(args) < 1:
- parser.print_help()
- sys.exit(1)
-
- if args[0] == "find-paths":
- find_paths(args[1:], parser.print_help)
- else:
- parser.print_help()
- sys.exit(1)
+ ret = args.func(args)
+ return ret
if __name__ == "__main__":
- main()
+ ret = main()
+ sys.exit(ret)