| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 from __future__ import print_function | 5 from __future__ import print_function |
| 6 | 6 |
| 7 import sys | 7 import sys |
| 8 | 8 |
| 9 from . import loader | 9 from . import loader |
| 10 | 10 |
| 11 from . import env | 11 from . import env |
| 12 | 12 |
| 13 import argparse # this is vendored | 13 import argparse # this is vendored |
| 14 | 14 |
| 15 | 15 |
| 16 _GRAPH_HEADER = """strict digraph { | 16 _GRAPH_HEADER = """strict digraph { |
| 17 concentrate = true; | 17 concentrate = true; |
| 18 ranksep = 2; | 18 ranksep = 2; |
| 19 nodesep = 0.25; | 19 nodesep = 0.25; |
| 20 """ | 20 """ |
| 21 | 21 |
| 22 _GRAPH_FOOTER = """} | 22 _GRAPH_FOOTER = """} |
| 23 """ | 23 """ |
| 24 | 24 |
| 25 | 25 |
| 26 def add_subparser(parser): | 26 def add_subparser(parser): |
| 27 depgraph_p = parser.add_parser( | 27 depgraph_p = parser.add_parser( |
| 28 'depgraph', | 28 'depgraph', |
| 29 description=( | 29 help='Produce graphviz graph of recipe and recipe module dependencies.', |
| 30 'Produce graph of recipe and recipe module dependencies. Example: ' | 30 description=( |
| 31 './recipes.py --package infra/config/recipes.cfg depgraph | tred | ' | 31 'Produce graphviz graph of recipe and recipe module dependencies. ' |
| 32 'dot -Tpdf > graph.pdf')) | 32 'Example: ./recipes.py --package infra/config/recipes.cfg depgraph | ' |
| 33 'tred | dot -Tpdf > graph.pdf')) |
| 33 depgraph_p.add_argument( | 34 depgraph_p.add_argument( |
| 34 '--output', type=argparse.FileType('w'), default=sys.stdout, | 35 '--output', type=argparse.FileType('w'), default=sys.stdout, |
| 35 help='The file to write output to') | 36 help='The file to write output to') |
| 36 depgraph_p.add_argument( | 37 depgraph_p.add_argument( |
| 37 '--ignore-package', action='append', default=[], | 38 '--ignore-package', action='append', default=[], |
| 38 dest='ignore_packages', | 39 dest='ignore_packages', |
| 39 help='Ignore a recipe package (e.g. recipe_engine). Can be passed ' | 40 help=( |
| 40 'multiple times') | 41 'Ignore a recipe package (e.g. recipe_engine). Can be passed ' |
| 42 'multiple times')) |
| 41 depgraph_p.add_argument( | 43 depgraph_p.add_argument( |
| 42 '--recipe-filter', default='', | 44 '--recipe-filter', default='', |
| 43 help='A recipe substring to examine. If present, the depgraph will ' | 45 help=( |
| 44 'include a recipe section containing recipes whose names contain ' | 46 'A recipe substring to examine. If present, the depgraph will ' |
| 45 'this substring. It will also filter all nodes of the graph to only ' | 47 'include a recipe section containing recipes whose names contain ' |
| 46 'include modules touched by the filtered recipes.') | 48 'this substring. It will also filter all nodes of the graph to only ' |
| 49 'include modules touched by the filtered recipes.')) |
| 47 | 50 |
| 48 depgraph_p.set_defaults(command='depgraph', func=main) | 51 depgraph_p.set_defaults(command='depgraph', func=main) |
| 49 | 52 |
| 50 | 53 |
| 51 def main(package_deps, args): | 54 def main(package_deps, args): |
| 52 universe = loader.RecipeUniverse(package_deps, args.package) | 55 universe = loader.RecipeUniverse(package_deps, args.package) |
| 53 own_package = package_deps.root_package | 56 own_package = package_deps.root_package |
| 54 | 57 |
| 55 module_to_package = {} | 58 module_to_package = {} |
| 56 | 59 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 print(' subgraph "cluster_%s" { label="%s"; %s; }' % ( | 142 print(' subgraph "cluster_%s" { label="%s"; %s; }' % ( |
| 140 package, package, '; '.join(modules)), file=args.output) | 143 package, package, '; '.join(modules)), file=args.output) |
| 141 | 144 |
| 142 if args.recipe_filter and recipe_to_package: | 145 if args.recipe_filter and recipe_to_package: |
| 143 recipe_names = [ | 146 recipe_names = [ |
| 144 '"recipe %s"' % name for name in recipe_to_package.keys()] | 147 '"recipe %s"' % name for name in recipe_to_package.keys()] |
| 145 print(' subgraph "cluster_recipes" { label="recipes"; %s; }' % ( | 148 print(' subgraph "cluster_recipes" { label="recipes"; %s; }' % ( |
| 146 '; '.join(recipe_names)), file=args.output) | 149 '; '.join(recipe_names)), file=args.output) |
| 147 | 150 |
| 148 print(_GRAPH_FOOTER, file=args.output) | 151 print(_GRAPH_FOOTER, file=args.output) |
| OLD | NEW |