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

Side by Side Diff: tools/gardening/lib/src/util.dart

Issue 2986223002: Add tests for BuildGroup names (Closed)
Patch Set: Updated cf. comments 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 unified diff | Download patch
« no previous file with comments | « tools/gardening/lib/src/client.dart ('k') | tools/gardening/test/buildbot_data_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:args/args.dart'; 9 import 'package:args/args.dart';
10 10
(...skipping 25 matching lines...) Expand all
36 if (text.length < length) return '${' ' * (length - text.length)}${text}'; 36 if (text.length < length) return '${' ' * (length - text.length)}${text}';
37 return text; 37 return text;
38 } 38 }
39 39
40 bool LOG = const bool.fromEnvironment('LOG', defaultValue: false); 40 bool LOG = const bool.fromEnvironment('LOG', defaultValue: false);
41 41
42 void log(Object text) { 42 void log(Object text) {
43 if (LOG) print(text); 43 if (LOG) print(text);
44 } 44 }
45 45
46 class HttpException implements Exception {
47 final Uri uri;
48 final int statusCode;
49
50 HttpException(this.uri, this.statusCode);
51
52 String toString() => '$uri: $statusCode';
53 }
54
46 /// Reads the content of [uri] as text. 55 /// Reads the content of [uri] as text.
47 Future<String> readUriAsText(HttpClient client, Uri uri) async { 56 Future<String> readUriAsText(HttpClient client, Uri uri) async {
48 HttpClientRequest request = await client.getUrl(uri); 57 HttpClientRequest request = await client.getUrl(uri);
49 HttpClientResponse response = await request.close(); 58 HttpClientResponse response = await request.close();
50 return await response.transform(UTF8.decoder).join(); 59 if (response.statusCode != 200) {
60 response.drain();
61 throw new HttpException(uri, response.statusCode);
62 }
63 return response.transform(UTF8.decoder).join();
51 } 64 }
52 65
53 ArgParser createArgParser() { 66 ArgParser createArgParser() {
54 ArgParser argParser = new ArgParser(allowTrailingOptions: true); 67 ArgParser argParser = new ArgParser(allowTrailingOptions: true);
55 argParser.addFlag('help', help: "Help"); 68 argParser.addFlag('help', help: "Help");
56 argParser.addFlag('verbose', 69 argParser.addFlag('verbose',
57 abbr: 'v', negatable: false, help: "Turn on logging output."); 70 abbr: 'v', negatable: false, help: "Turn on logging output.");
58 argParser.addFlag('no-cache', help: "Disable caching."); 71 argParser.addFlag('no-cache', help: "Disable caching.");
59 argParser.addOption('cache', 72 argParser.addOption('cache',
60 help: "Use <dir> for caching test output.\n" 73 help: "Use <dir> for caching test output.\n"
61 "Defaults to 'temp/gardening-cache/'."); 74 "Defaults to 'temp/gardening-cache/'.");
62 argParser.addFlag('logdog', 75 argParser.addFlag('logdog',
63 negatable: false, help: "Pull test results from logdog."); 76 negatable: false, help: "Pull test results from logdog.");
64 return argParser; 77 return argParser;
65 } 78 }
66 79
67 void processArgResults(ArgResults argResults) { 80 void processArgResults(ArgResults argResults) {
68 if (argResults['verbose']) { 81 if (argResults['verbose']) {
69 LOG = true; 82 LOG = true;
70 } 83 }
71 if (argResults['cache'] != null) { 84 if (argResults['cache'] != null) {
72 cache.base = Uri.base.resolve('${argResults['cache']}/'); 85 cache.base = Uri.base.resolve('${argResults['cache']}/');
73 } 86 }
74 if (argResults['no-cache']) { 87 if (argResults['no-cache']) {
75 cache.base = null; 88 cache.base = null;
76 } 89 }
77 } 90 }
OLDNEW
« no previous file with comments | « tools/gardening/lib/src/client.dart ('k') | tools/gardening/test/buildbot_data_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698