Added graphviz visualization.
This commit is contained in:
		
							parent
							
								
									8ee6e9625d
								
							
						
					
					
						commit
						59e4bc424e
					
				
					 5 changed files with 47 additions and 1 deletions
				
			
		|  | @ -24,6 +24,13 @@ class Args: | ||||||
|             return result |             return result | ||||||
|         return default |         return default | ||||||
| 
 | 
 | ||||||
|  |     def tryConsumeOpt(self, key: str) -> Value | None: | ||||||
|  |         if key in self.opts: | ||||||
|  |             result = self.opts[key] | ||||||
|  |             del self.opts[key] | ||||||
|  |             return result | ||||||
|  |         return None | ||||||
|  | 
 | ||||||
|     def consumeArg(self) -> str | None: |     def consumeArg(self) -> str | None: | ||||||
|         if len(self.args) == 0: |         if len(self.args) == 0: | ||||||
|             return None |             return None | ||||||
|  |  | ||||||
							
								
								
									
										15
									
								
								osdk/cmds.py
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								osdk/cmds.py
									
										
									
									
									
								
							|  | @ -1,7 +1,8 @@ | ||||||
| from typing import Callable, cast | from typing import Callable, cast | ||||||
| 
 | 
 | ||||||
| from osdk.args import Args | from osdk.args import Args | ||||||
| from osdk import context, shell, const, vt100, builder | from osdk.context import contextFor | ||||||
|  | from osdk import context, shell, const, vt100, builder, graph | ||||||
| 
 | 
 | ||||||
| Callback = Callable[[Args], None] | Callback = Callable[[Args], None] | ||||||
| 
 | 
 | ||||||
|  | @ -136,6 +137,18 @@ def versionCmd(args: Args): | ||||||
| cmds += [Cmd("v", "version", "Show current version", versionCmd)] | cmds += [Cmd("v", "version", "Show current version", versionCmd)] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def graphCmd(args: Args): | ||||||
|  |     targetSpec = cast(str, args.consumeOpt( | ||||||
|  |         "target", "host-" + shell.uname().machine)) | ||||||
|  | 
 | ||||||
|  |     context = contextFor(targetSpec, {}) | ||||||
|  | 
 | ||||||
|  |     graph.view(context) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | cmds += [Cmd("g", "graph", "Show dependency graph", graphCmd)] | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def usage(): | def usage(): | ||||||
|     print(f"Usage: {const.ARGV0} <command> [args...]") |     print(f"Usage: {const.ARGV0} <command> [args...]") | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -79,6 +79,9 @@ class Context: | ||||||
|     def cdefs(self) -> list[str]: |     def cdefs(self) -> list[str]: | ||||||
|         return self.target.cdefs() |         return self.target.cdefs() | ||||||
| 
 | 
 | ||||||
|  |     def builddir(self) -> str: | ||||||
|  |         return self.target.builddir() | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def loadAllTargets() -> list[TargetManifest]: | def loadAllTargets() -> list[TargetManifest]: | ||||||
|     files = shell.find(const.TARGETS_DIR, ["*.json"]) |     files = shell.find(const.TARGETS_DIR, ["*.json"]) | ||||||
|  |  | ||||||
							
								
								
									
										22
									
								
								osdk/graph.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								osdk/graph.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | ||||||
|  | from graphviz import Digraph | ||||||
|  | 
 | ||||||
|  | from osdk.context import Context | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def view(context: Context): | ||||||
|  |     g = Digraph(context.target.id, filename='graph.gv') | ||||||
|  |      | ||||||
|  |     g.attr('node', shape='ellipse') | ||||||
|  | 
 | ||||||
|  |     for instance in context.instances: | ||||||
|  |         if not instance.isLib(): | ||||||
|  |             continue | ||||||
|  |         g.node(instance.manifest.id, f"<<B>{instance.manifest.id}</B><BR/>{instance.manifest.decription}>", | ||||||
|  |                shape="plaintext", style="filled") | ||||||
|  |         for req in instance.manifest.requires: | ||||||
|  |             g.edge(req, instance.manifest.id) | ||||||
|  | 
 | ||||||
|  |         for req in instance.manifest.provides: | ||||||
|  |             g.edge(instance.manifest.id, req) | ||||||
|  | 
 | ||||||
|  |     g.view(filename=f"{context.builddir()}/graph.gv") | ||||||
							
								
								
									
										1
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								setup.py
									
										
									
									
									
								
							|  | @ -12,6 +12,7 @@ setup( | ||||||
|     packages=["osdk"], |     packages=["osdk"], | ||||||
|     install_requires=[ |     install_requires=[ | ||||||
|         "requests", |         "requests", | ||||||
|  |         "graphviz" | ||||||
|     ], |     ], | ||||||
|     entry_points={ |     entry_points={ | ||||||
|         "console_scripts": [ |         "console_scripts": [ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue