| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env dart |
| 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. |
| 5 |
| 6 /** |
| 7 * A simple script that updates a target json file with the new values from |
| 8 * another json file. |
| 9 */ |
| 10 library test.perf.update_json; |
| 11 |
| 12 import 'dart:io'; |
| 13 import 'dart:json'; |
| 14 import 'dart:math' as math; |
| 15 |
| 16 main() { |
| 17 var args = new Options().arguments; |
| 18 if (args.length < 2) { |
| 19 print('update_json.dart: A simple script that updates a target json file ' |
| 20 'with the new values from another json file. '); |
| 21 print('usage: update.dart from.json to.json'); |
| 22 exit(1); |
| 23 } |
| 24 |
| 25 var path1 = args[0]; |
| 26 var path2 = args[1]; |
| 27 var file1 = new File(path1).readAsStringSync(); |
| 28 var file2 = new File(path2).readAsStringSync(); |
| 29 |
| 30 var results = []; |
| 31 var map1 = JSON.parse(file1); |
| 32 var map2 = JSON.parse(file2); |
| 33 |
| 34 for (var key in map1.keys) { |
| 35 if (map1[key] != null) { |
| 36 map2[key] = map1[key]; |
| 37 } |
| 38 } |
| 39 |
| 40 print('updating $path2...'); |
| 41 _writeFile(path2, JSON.stringify(map2)); |
| 42 } |
| 43 |
| 44 Future _writeFile(String path, String text) { |
| 45 return new File(path).open(FileMode.WRITE) |
| 46 .chain((file) => file.writeString(text)) |
| 47 .chain((file) => file.close()); |
| 48 } |
| OLD | NEW |