Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/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.
| |
| 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 | |
|
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
| |
| 8 * another json file. | |
| 9 */ | |
|
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.
| |
| 10 | |
| 11 import 'dart:io'; | |
| 12 import 'dart:json'; | |
| 13 import 'dart:math' as math; | |
| 14 | |
| 15 main() { | |
| 16 var args = new Options().arguments; | |
| 17 if (args.length < 2) { | |
| 18 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.
| |
| 19 exit(1); | |
| 20 } | |
| 21 | |
| 22 var path1 = args[0]; | |
| 23 var path2 = args[1]; | |
| 24 var file1 = new File(path1).readAsStringSync(); | |
| 25 var file2 = new File(path2).readAsStringSync(); | |
| 26 | |
| 27 var results = []; | |
| 28 var map1 = JSON.parse(file1); | |
| 29 var map2 = JSON.parse(file2); | |
| 30 | |
| 31 for (var key in map1.keys) { | |
| 32 if (map1[key] != null) { | |
| 33 map2[key] = map1[key]; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 print('updating $path2...'); | |
| 38 _writeFile(path2, JSON.stringify(map2)); | |
| 39 } | |
| 40 | |
| 41 Future _writeFile(String path, String text) { | |
| 42 return new File(path).open(FileMode.WRITE) | |
| 43 .chain((file) => file.writeString(text)) | |
| 44 .chain((file) => file.close()); | |
| 45 } | |
| OLD | NEW |