|
| 1 | +// Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
1 | 5 | import 'dart:async'; |
2 | 6 | import 'dart:convert'; |
3 | 7 | import 'dart:io'; |
@@ -56,6 +60,7 @@ class Upload { |
56 | 60 |
|
57 | 61 | final HttpClientResponse response = await request.close().timeout(timeLimit); |
58 | 62 | if (response.statusCode == HttpStatus.OK) { |
| 63 | + logMessage('Saved $name'); |
59 | 64 | await response.drain<Null>(); |
60 | 65 | } else { |
61 | 66 | // TODO(hansmuller): only retry on 5xx and 429 responses |
@@ -96,40 +101,40 @@ Future<Null> saveScreenshots(List<String> fromPaths, List<String> largeNames, Li |
96 | 101 | for (int index = 0; index < uploads.length; index += 1) |
97 | 102 | uploads[index] = new Upload(fromPaths[index], largeNames[index], smallNames[index]); |
98 | 103 |
|
99 | | - final HttpClient client = new HttpClient(); |
100 | 104 | while(uploads.any(Upload.isNotComplete)) { |
| 105 | + final HttpClient client = new HttpClient(); |
101 | 106 | uploads = uploads.where(Upload.isNotComplete).toList(); |
102 | 107 | await Future.wait(uploads.map((Upload upload) => upload.run(client))); |
| 108 | + client.close(force: true); |
103 | 109 | } |
104 | | - client.close(); |
105 | 110 | } |
106 | 111 |
|
107 | 112 |
|
108 | 113 | // If path is lib/foo.png then screenshotName is foo. |
109 | 114 | String screenshotName(String path) => basenameWithoutExtension(path); |
110 | 115 |
|
111 | | -Future<Null> main(List<String> args) async { |
112 | | - if (args.length != 2) |
113 | | - throw new UploadError('Usage: dart bin/save_screenshots.dart commit authorization'); |
114 | | - |
115 | | - final Directory outputDirectory = new Directory('.generated'); |
| 116 | +Future<Null> saveCatalogScreenshots({ |
| 117 | + Directory directory, // Where the *.png screenshots are. |
| 118 | + String commit, // The commit hash to be used as a cloud storage "directory". |
| 119 | + String token, // Cloud storage authorization token. |
| 120 | + String prefix, // Prefix for all file names. |
| 121 | + }) async { |
116 | 122 | final List<String> screenshots = <String>[]; |
117 | | - outputDirectory.listSync().forEach((FileSystemEntity entity) { |
| 123 | + directory.listSync().forEach((FileSystemEntity entity) { |
118 | 124 | if (entity is File && entity.path.endsWith('.png')) { |
119 | 125 | final File file = entity; |
120 | 126 | screenshots.add(file.path); |
121 | 127 | } |
122 | 128 | }); |
123 | 129 |
|
124 | | - final String commit = args[0]; |
125 | 130 | final List<String> largeNames = <String>[]; // Cloud storage names for the full res screenshots. |
126 | 131 | final List<String> smallNames = <String>[]; // Likewise for the scaled down screenshots. |
127 | 132 | for (String path in screenshots) { |
128 | 133 | final String name = screenshotName(path); |
129 | | - largeNames.add('$commit/$name.png'); |
130 | | - smallNames.add('$commit/${name}_small.png'); |
| 134 | + largeNames.add('$commit/$prefix$name.png'); |
| 135 | + smallNames.add('$commit/$prefix${name}_small.png'); |
131 | 136 | } |
132 | 137 |
|
133 | | - authorizationToken = args[1]; |
| 138 | + authorizationToken = token; |
134 | 139 | await saveScreenshots(screenshots, largeNames, smallNames); |
135 | 140 | } |
0 commit comments