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

Side by Side Diff: tools/gardening/bin/luci_api.dart

Issue 3005443002: Additional tools for gardening. (Closed)
Patch Set: Moved files from gardening_tools to gardening and incorporated changes from johnniwinther Created 3 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 import 'dart:async';
Johnni Winther 2017/08/28 07:14:03 Just call this file 'luci.dart' - we're using it f
2
3 import 'package:gardening/src/luci_api.dart';
4 import 'package:gardening/src/luci_services.dart';
5 import 'package:gardening/src/logger.dart';
6 import 'package:gardening/src/cache_new.dart';
7 import 'package:args/args.dart';
8
9 ArgParser setupArgs() {
10 return new ArgParser()
11 ..addOption("client",
12 abbr: "c", defaultsTo: 'client.dart', help: "Set which client to use.")
13 ..addFlag("verbose",
14 abbr: "v", negatable: false, help: "Print debugging information.")
15 ..addFlag("no-cache",
16 negatable: false,
17 defaultsTo: false,
18 help: "Use this flag to bypass caching. This may be slower.")
19 ..addFlag("help",
20 negatable: false,
21 help: "Shows information on how to use the luci_api tool.")
22 ..addFlag("build-bots",
23 negatable: false,
24 help: "Use this flag to see the primary build bots for --client.")
25 ..addFlag("build-bots-all",
26 negatable: false,
27 help: "Use this flag to see all build bots for --client.")
28 ..addFlag("build-bot-details",
29 negatable: false,
30 help: "Use this flag as `--build-bot-details <name>` where "
31 "<name> is the name of the build bot, to see details of "
32 "a specific build bot.")
33 ..addFlag("build-details",
34 negatable: false,
35 help: "use this option as `--build-details <name> <buildNo>` where "
36 "<name> is the name of the bot and "
37 "<buildNo> is the number of the build.")
38 ..addFlag("commit-builds",
39 negatable: false,
40 help: "Fetches all builds for a specific commit. Use this flag as "
41 "`--commit-builds <commit-hash>` where the <commit-hash> is the hash "
Johnni Winther 2017/08/28 07:14:03 Long line.
42 "of the commit");
43 }
44
45 void printHelp(ArgParser parser) {
46 print(
47 "This tool calls different pages on Luci and aggregate the information fou nd. "
Johnni Winther 2017/08/28 07:14:03 Long line.
48 "Below is stated information about individual flags and options:");
49 print("");
50 print(parser.usage);
51 }
52
53 main(List<String> args) async {
54 var parser = setupArgs();
55 var results = parser.parse(args);
56
57 if (results["help"]) {
58 printHelp(parser);
59 return;
60 }
61
62 var luciApi = new LuciApi();
63 Logger logger =
64 new StdOutLogger(results['verbose'] ? Level.debug : Level.info);
65 CreateCacheFunction createCache = results['no-cache']
66 ? noCache()
67 : initCache(Uri.base.resolve('temp/gardening-cache/'), logger);
68
69 if (results["build-bots"]) {
70 await performBuildBotsPrimary(luciApi, createCache, results);
71 } else if (results["build-bots-all"]) {
72 await performBuildBotsAll(luciApi, createCache, results);
73 } else if (results["build-bot-details"]) {
74 await performBuildBotDetails(luciApi, createCache, results);
75 } else if (results["build-details"]) {
76 await performBuildDetails(luciApi, createCache, results);
77 } else if (results["commit-builds"]) {
78 await performFindBuildsForCommit(luciApi, createCache, logger, results);
79 } else {
80 printHelp(parser);
81 }
82
83 luciApi.close();
84 }
85
86 Future performBuildBotsPrimary(
87 LuciApi api, CreateCacheFunction createCache, ArgResults results) async {
88 var res = await api.getPrimaryBuilders(
89 results['client'], createCache(duration: new Duration(hours: 1)));
90 res.fold((ex, stackTrace) {
91 print(ex);
92 print(stackTrace);
93 }, (bots) => bots.forEach(print));
94 }
95
96 Future performBuildBotsAll(
97 LuciApi api, CreateCacheFunction cache, ArgResults results) async {
98 var res = await api.getAllBuildBots(
99 results['client'], cache(duration: new Duration(hours: 1)));
100 res.fold((ex, stackTrace) {
101 print(ex);
102 print(stackTrace);
103 }, (bots) => bots.forEach(print));
104 }
105
106 Future performBuildBotDetails(
107 LuciApi api, CreateCacheFunction cache, ArgResults results) async {
108 if (results.rest.length == 0) {
109 print("No argument given for <name>. To see help, use --help");
110 return;
111 }
112 var result = await api.getBuildBotDetails(results['client'], results.rest[0],
113 cache(duration: new Duration(minutes: 15)));
114 result.fold((ex, stackTrace) {
115 print(ex);
116 print(stackTrace);
117 }, (detail) => print(detail));
118 }
119
120 Future performBuildDetails(
121 LuciApi api, CreateCacheFunction createCache, ArgResults results) async {
122 if (results.rest.length < 2) {
123 print("Missing argument for <name> or <buildNo>. To see help, use --help");
124 return;
125 }
126 int buildNumber = int.parse(results.rest[1], onError: (source) => 0);
127 if (buildNumber <= 0) {
128 print("The buildnumber ${results['build-details']} must be a true integer "
Johnni Winther 2017/08/28 07:14:03 a true integer -> an integer
129 "greater than zero");
130 return;
131 }
132
133 var result = await api.getBuildBotBuildDetails(
134 results['client'],
135 results.rest[0],
136 buildNumber,
137 createCache(duration: new Duration(minutes: 15)));
138 result.fold((ex, stackTrace) {
139 print(ex);
140 print(stackTrace);
141 }, (detail) => print(detail));
142 }
143
144 Future performFindBuildsForCommit(LuciApi api, CreateCacheFunction createCache,
145 Logger logger, ArgResults results) async {
146 if (results.rest.length == 0) {
147 print("Missing argument for <commit>. To see help, use --help");
148 return;
149 }
150
151 int amount = 25;
152 logger.info(
153 "Sorry - this is going to take some time, since we have to look into all "
154 "$amount latest builds for all bots for client ${results['client']}.\n"
155 "Subsequent queries run faster if caching is not turned off...");
156
157 var result = await fetchBuildsForCommmit(
158 api, logger, results['client'], results.rest[0], createCache, amount);
159 result.fold((ex, st) {
160 print(ex);
161 print(st);
162 }, (List<BuildDetail> details) {
163 print("The commit '${results.rest[0]} is used in the following builds:");
164 details.forEach((detail) {
165 String url =
166 "https://luci-milo.appspot.com/buildbot/${detail.client}/${detail.botN ame}/${detail.buildNumber}";
167 print("${detail.botName}: #${detail.buildNumber}\t$url");
Johnni Winther 2017/08/28 07:14:02 Long line.
168 });
169 });
170 }
OLDNEW
« no previous file with comments | « no previous file | tools/gardening/lib/src/_luci_api.dart » ('j') | tools/gardening/lib/src/_luci_api.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698