Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: tools/gardening_tools/luci_api/bin/luci_api.dart

Issue 3005443002: Additional tools for gardening. (Closed)
Patch Set: Removed accidental commit Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/gardening_tools/luci_api/bin/luci_api.dart
diff --git a/tools/gardening_tools/luci_api/bin/luci_api.dart b/tools/gardening_tools/luci_api/bin/luci_api.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5a6c42ca926751889c72477da641d87f607b30d1
--- /dev/null
+++ b/tools/gardening_tools/luci_api/bin/luci_api.dart
@@ -0,0 +1,136 @@
+import 'dart:async';
+
+import 'package:luci_api/luci_api.dart';
+import 'package:base_lib/base_lib.dart';
+import 'package:args/args.dart';
+
+ArgParser setupArgs() {
+ return new ArgParser()
+ ..addOption("client",
+ abbr: "c", defaultsTo: 'client.dart', help: "Set which client to use.")
+ ..addFlag("verbose",
+ abbr: "v", negatable: false, help: "Print out debugging information")
Johnni Winther 2017/08/23 12:40:48 -> "Print debugging information." Generally, cons
+ ..addFlag("no-cache",
+ negatable: false,
+ defaultsTo: false,
+ help: "Use flag to bypass caching. This may be slower.")
+ ..addFlag("help", negatable: false, help: "Will show how to use the tool")
+ ..addFlag("build-bots",
+ negatable: false,
+ 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 ...
+ ..addFlag("build-bots-all",
+ negatable: false,
+ help: "Use this flag to see all build bots for --client")
+ ..addFlag("build-bot-details",
+ negatable: false,
+ help:
+ "use this flag as --build-bot-details <name> where <name> is the name of the build bot")
Johnni Winther 2017/08/23 12:40:48 -> ... as `--build-bot-details <name>` where <name
+ ..addFlag("build-details",
+ negatable: false,
+ help:
+ "use this option as --build-details <name> <buildNo> where <name> is the name of the bot and <buildNo> is the number of the build")
+ ..addFlag("commit-builds",
+ negatable: false,
+ help:
+ "Fetches all builds for a specific commit.. Use this flag as --commit-builds <commit-hash> where the <commit-hash> is the hash of the commit");
Johnni Winther 2017/08/23 12:40:48 -> ... specific commit. Use ...
+}
+
+main(List<String> args) async {
+ var parser = setupArgs();
+ var results = parser.parse(args);
+
+ if (results["help"]) {
+ print(
+ "This tool calls different pages on Luci and aggregate the information found. Below is stated information about individual flags and options:");
+ print("");
+ print(parser.usage);
+ return;
+ }
+
+ Logger logger =
+ new StdOutLogger(results['verbose'] ? Level.debug : Level.info);
+ PerformWithCache withCache = results['no-cache']
+ ? noCache()
+ : initCache(Uri.base.resolve('temp/gardening-cache/'), logger);
+ var luciApi = new LuciApi();
+
+ if (results["build-bots"]) {
+ await performBuildBotsPrimary(luciApi, withCache, results);
+ } else if (results["build-bots-all"]) {
+ await performBuildBotsAll(luciApi, withCache, results);
+ } else if (results["build-bot-details"]) {
+ await performBuildBotDetails(luciApi, withCache, results);
+ } else if (results["build-details"]) {
+ await performBuildDetails(luciApi, withCache, results);
+ } else if (results["commit-builds"]) {
+ await performFindBuildsForCommit(luciApi, withCache, logger, results);
+ } else {
+ print("No command found. Use --help for more information.");
Johnni Winther 2017/08/23 12:40:47 Just print the help here.
+ }
+
+ luciApi.close();
+}
+
+Future performBuildBotsPrimary(
+ LuciApi api, PerformWithCache cache, ArgResults results) async {
+ var res = await api.getPrimaryBuilders(
+ results['client'], cache(duration: new Duration(hours: 1)));
+ res.fold((ex) => print(ex), (bots) => bots.forEach(print));
+}
+
+Future performBuildBotsAll(
+ LuciApi api, PerformWithCache cache, ArgResults results) async {
+ var res = await api.getAllBuildBots(
+ results['client'], cache(duration: new Duration(hours: 1)));
+ res.fold((ex) => print(ex), (bots) => bots.forEach(print));
+}
+
+Future performBuildBotDetails(
+ LuciApi api, PerformWithCache cache, ArgResults results) async {
+ if (results.rest.length == 0) {
+ print("No argument given for <name>. To see help, use --help");
+ return;
+ }
+
+ var result = await api.getBuildBotDetails(results['client'], results.rest[0],
+ cache(duration: new Duration(minutes: 15)));
+ result.fold((ex) => print(ex), (detail) => print(detail));
+}
+
+Future performBuildDetails(
+ LuciApi api, PerformWithCache cache, ArgResults results) async {
+ if (results.rest.length < 2) {
+ print("Missing argument for <name> or <buildNo>. To see help, use --help");
+ return;
+ }
+
+ int buildNumber = int.parse(results.rest[1], onError: (source) => 0);
+ if (buildNumber <= 0) {
+ print(
+ "The buildnumber ${results['build-details']} must be a true integer greater than zero");
+ return;
+ }
+
+ var result = await api.getBuildDetails(results['client'], results.rest[0],
+ buildNumber, cache(duration: new Duration(minutes: 15)));
+ result.fold((ex) => print(ex), (detail) => print(detail));
+}
+
+Future performFindBuildsForCommit(LuciApi api, PerformWithCache cache,
+ Logger logger, ArgResults results) async {
+ if (results.rest.length == 0) {
+ print("Missing argument for <commit>. To see help, use --help");
+ return;
+ }
+
+ var result = await fetchBuildsForCommmit(
+ api, logger, results['client'], results.rest[0], cache);
+ result.fold((ex) => print(ex), (List<BuildDetail> details) {
+ print("The commit '${results.rest[0]} is used in the following builds:");
+ details.forEach((detail) {
+ String url =
+ "https://luci-milo.appspot.com/buildbot/${detail.client}/${detail.botName}/${detail.buildNumber}";
+ print("${detail.botName}: #${detail.buildNumber}\t$url");
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698