OLD | NEW |
1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 4 # found in the LICENSE file. |
4 | 5 |
5 # Splits a single json file (read from stdin) into separate files of 40k | 6 """Splits a single json file (read from stdin) into separate files of 40k |
6 # records, named split.X. | 7 records, named split.X. |
| 8 """ |
7 | 9 |
8 import sys | 10 import sys |
9 | 11 |
10 filecount = 0; | |
11 count = 0; | |
12 | 12 |
13 f = open('split.0', 'wb'); | 13 def main(): |
| 14 filecount = 0 |
| 15 count = 0 |
| 16 f = open('split.0', 'wb') |
| 17 for l in sys.stdin: |
| 18 if l == "},\r\n": |
| 19 count += 1 |
| 20 if count == 40000: |
| 21 f.write("}]);\r\n") |
| 22 count = 0 |
| 23 filecount += 1 |
| 24 f = open('split.%d' % filecount, 'wb') |
| 25 f.write("parseEvents([\r\n") |
| 26 continue |
| 27 f.write(l) |
14 | 28 |
15 for l in sys.stdin: | 29 |
16 if l == "},\r\n": | 30 if __name__ == '__main__': |
17 count += 1 | 31 main() |
18 if count == 40000: | |
19 f.write("}]);\r\n") | |
20 count = 0; | |
21 filecount += 1 | |
22 f = open('split.%d' % filecount, 'wb'); | |
23 f.write("parseEvents([\r\n") | |
24 continue | |
25 f.write(l) | |
OLD | NEW |