Chromium Code Reviews| Index: test/perf/update.dart |
| diff --git a/test/perf/update.dart b/test/perf/update.dart |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..4b527ff0254d58bd70e6d08e66e7c84ac1383ebc |
| --- /dev/null |
| +++ b/test/perf/update.dart |
| @@ -0,0 +1,45 @@ |
| +#!/usr/bin/env dart |
|
Jennifer Messerly
2013/01/07 21:07:46
rename this script to update_json or copy_json?
Siggi Cherem (dart-lang)
2013/01/08 02:26:18
Done.
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +/** |
| + * A simple script that updates a target json file with the new values from |
|
Jennifer Messerly
2013/01/07 21:07:46
I might've missed where this is called from?
Siggi Cherem (dart-lang)
2013/01/08 02:26:18
nowhere - it's an utility script used from the com
|
| + * another json file. |
| + */ |
|
Jennifer Messerly
2013/01/07 21:07:46
library tag, so this comment has something to be a
Siggi Cherem (dart-lang)
2013/01/08 02:26:18
Done.
|
| + |
| +import 'dart:io'; |
| +import 'dart:json'; |
| +import 'dart:math' as math; |
| + |
| +main() { |
| + var args = new Options().arguments; |
| + if (args.length < 2) { |
| + print('usage: update.dart from.json to.json'); |
|
Jennifer Messerly
2013/01/07 21:07:46
Would be nice to print the nice library comment he
Siggi Cherem (dart-lang)
2013/01/08 02:26:18
Done.
|
| + exit(1); |
| + } |
| + |
| + var path1 = args[0]; |
| + var path2 = args[1]; |
| + var file1 = new File(path1).readAsStringSync(); |
| + var file2 = new File(path2).readAsStringSync(); |
| + |
| + var results = []; |
| + var map1 = JSON.parse(file1); |
| + var map2 = JSON.parse(file2); |
| + |
| + for (var key in map1.keys) { |
| + if (map1[key] != null) { |
| + map2[key] = map1[key]; |
| + } |
| + } |
| + |
| + print('updating $path2...'); |
| + _writeFile(path2, JSON.stringify(map2)); |
| +} |
| + |
| +Future _writeFile(String path, String text) { |
| + return new File(path).open(FileMode.WRITE) |
| + .chain((file) => file.writeString(text)) |
| + .chain((file) => file.close()); |
| +} |