Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 import 'dart:async'; | |
| 2 | |
| 3 import 'package:luci_api/luci_api.dart'; | |
| 4 import 'package:base_lib/base_lib.dart'; | |
| 5 import 'package:args/args.dart'; | |
| 6 | |
| 7 ArgParser setupArgs() { | |
| 8 return new ArgParser() | |
| 9 ..addOption("client", | |
| 10 abbr: "c", defaultsTo: 'client.dart', help: "Set which client to use.") | |
| 11 ..addFlag("verbose", | |
| 12 abbr: "v", negatable: false, help: "Print out debugging information") | |
|
Johnni Winther
2017/08/23 12:40:48
-> "Print debugging information."
Generally, cons
| |
| 13 ..addFlag("no-cache", | |
| 14 negatable: false, | |
| 15 defaultsTo: false, | |
| 16 help: "Use flag to bypass caching. This may be slower.") | |
| 17 ..addFlag("help", negatable: false, help: "Will show how to use the tool") | |
| 18 ..addFlag("build-bots", | |
| 19 negatable: false, | |
| 20 help: "Use this flag to see the primary build bots for --client") | |
|
Johnni Winther
2017/08/23 12:40:47
-> ... the most recent build bots ...
| |
| 21 ..addFlag("build-bots-all", | |
| 22 negatable: false, | |
| 23 help: "Use this flag to see all build bots for --client") | |
| 24 ..addFlag("build-bot-details", | |
| 25 negatable: false, | |
| 26 help: | |
| 27 "use this flag as --build-bot-details <name> where <name> is the nam e of the build bot") | |
|
Johnni Winther
2017/08/23 12:40:48
-> ... as `--build-bot-details <name>` where <name
| |
| 28 ..addFlag("build-details", | |
| 29 negatable: false, | |
| 30 help: | |
| 31 "use this option as --build-details <name> <buildNo> where <name> is the name of the bot and <buildNo> is the number of the build") | |
| 32 ..addFlag("commit-builds", | |
| 33 negatable: false, | |
| 34 help: | |
| 35 "Fetches all builds for a specific commit.. Use this flag as --commi t-builds <commit-hash> where the <commit-hash> is the hash of the commit"); | |
|
Johnni Winther
2017/08/23 12:40:48
-> ... specific commit. Use ...
| |
| 36 } | |
| 37 | |
| 38 main(List<String> args) async { | |
| 39 var parser = setupArgs(); | |
| 40 var results = parser.parse(args); | |
| 41 | |
| 42 if (results["help"]) { | |
| 43 print( | |
| 44 "This tool calls different pages on Luci and aggregate the information f ound. Below is stated information about individual flags and options:"); | |
| 45 print(""); | |
| 46 print(parser.usage); | |
| 47 return; | |
| 48 } | |
| 49 | |
| 50 Logger logger = | |
| 51 new StdOutLogger(results['verbose'] ? Level.debug : Level.info); | |
| 52 PerformWithCache withCache = results['no-cache'] | |
| 53 ? noCache() | |
| 54 : initCache(Uri.base.resolve('temp/gardening-cache/'), logger); | |
| 55 var luciApi = new LuciApi(); | |
| 56 | |
| 57 if (results["build-bots"]) { | |
| 58 await performBuildBotsPrimary(luciApi, withCache, results); | |
| 59 } else if (results["build-bots-all"]) { | |
| 60 await performBuildBotsAll(luciApi, withCache, results); | |
| 61 } else if (results["build-bot-details"]) { | |
| 62 await performBuildBotDetails(luciApi, withCache, results); | |
| 63 } else if (results["build-details"]) { | |
| 64 await performBuildDetails(luciApi, withCache, results); | |
| 65 } else if (results["commit-builds"]) { | |
| 66 await performFindBuildsForCommit(luciApi, withCache, logger, results); | |
| 67 } else { | |
| 68 print("No command found. Use --help for more information."); | |
|
Johnni Winther
2017/08/23 12:40:47
Just print the help here.
| |
| 69 } | |
| 70 | |
| 71 luciApi.close(); | |
| 72 } | |
| 73 | |
| 74 Future performBuildBotsPrimary( | |
| 75 LuciApi api, PerformWithCache cache, ArgResults results) async { | |
| 76 var res = await api.getPrimaryBuilders( | |
| 77 results['client'], cache(duration: new Duration(hours: 1))); | |
| 78 res.fold((ex) => print(ex), (bots) => bots.forEach(print)); | |
| 79 } | |
| 80 | |
| 81 Future performBuildBotsAll( | |
| 82 LuciApi api, PerformWithCache cache, ArgResults results) async { | |
| 83 var res = await api.getAllBuildBots( | |
| 84 results['client'], cache(duration: new Duration(hours: 1))); | |
| 85 res.fold((ex) => print(ex), (bots) => bots.forEach(print)); | |
| 86 } | |
| 87 | |
| 88 Future performBuildBotDetails( | |
| 89 LuciApi api, PerformWithCache cache, ArgResults results) async { | |
| 90 if (results.rest.length == 0) { | |
| 91 print("No argument given for <name>. To see help, use --help"); | |
| 92 return; | |
| 93 } | |
| 94 | |
| 95 var result = await api.getBuildBotDetails(results['client'], results.rest[0], | |
| 96 cache(duration: new Duration(minutes: 15))); | |
| 97 result.fold((ex) => print(ex), (detail) => print(detail)); | |
| 98 } | |
| 99 | |
| 100 Future performBuildDetails( | |
| 101 LuciApi api, PerformWithCache cache, ArgResults results) async { | |
| 102 if (results.rest.length < 2) { | |
| 103 print("Missing argument for <name> or <buildNo>. To see help, use --help"); | |
| 104 return; | |
| 105 } | |
| 106 | |
| 107 int buildNumber = int.parse(results.rest[1], onError: (source) => 0); | |
| 108 if (buildNumber <= 0) { | |
| 109 print( | |
| 110 "The buildnumber ${results['build-details']} must be a true integer grea ter than zero"); | |
| 111 return; | |
| 112 } | |
| 113 | |
| 114 var result = await api.getBuildDetails(results['client'], results.rest[0], | |
| 115 buildNumber, cache(duration: new Duration(minutes: 15))); | |
| 116 result.fold((ex) => print(ex), (detail) => print(detail)); | |
| 117 } | |
| 118 | |
| 119 Future performFindBuildsForCommit(LuciApi api, PerformWithCache cache, | |
| 120 Logger logger, ArgResults results) async { | |
| 121 if (results.rest.length == 0) { | |
| 122 print("Missing argument for <commit>. To see help, use --help"); | |
| 123 return; | |
| 124 } | |
| 125 | |
| 126 var result = await fetchBuildsForCommmit( | |
| 127 api, logger, results['client'], results.rest[0], cache); | |
| 128 result.fold((ex) => print(ex), (List<BuildDetail> details) { | |
| 129 print("The commit '${results.rest[0]} is used in the following builds:"); | |
| 130 details.forEach((detail) { | |
| 131 String url = | |
| 132 "https://luci-milo.appspot.com/buildbot/${detail.client}/${detail.botN ame}/${detail.buildNumber}"; | |
| 133 print("${detail.botName}: #${detail.buildNumber}\t$url"); | |
| 134 }); | |
| 135 }); | |
| 136 } | |
| OLD | NEW |