OLD | NEW |
| 1 #!/usr/bin/env python |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 import sys | 6 import sys |
6 | 7 |
7 from autofill_merge_common import SerializeProfiles, ColumnNameToFieldType | 8 from autofill_merge_common import SerializeProfiles, ColumnNameToFieldType |
8 | 9 |
| 10 |
9 def main(): | 11 def main(): |
10 """Serializes the output of the query 'SELECT * from autofill_profiles;'. | 12 """Serializes the output of the query 'SELECT * from autofill_profiles;'. |
11 | |
12 """ | 13 """ |
13 | 14 |
14 COLUMNS = ['GUID', 'LABEL', 'FIRST_NAME', 'MIDDLE_NAME', 'LAST_NAME', 'EMAIL', | 15 COLUMNS = ['GUID', 'LABEL', 'FIRST_NAME', 'MIDDLE_NAME', 'LAST_NAME', 'EMAIL', |
15 'COMPANY_NAME', 'ADDRESS_LINE_1', 'ADDRESS_LINE_2', 'CITY', | 16 'COMPANY_NAME', 'ADDRESS_LINE_1', 'ADDRESS_LINE_2', 'CITY', |
16 'STATE', 'ZIPCODE', 'COUNTRY', 'PHONE', 'DATE_MODIFIED'] | 17 'STATE', 'ZIPCODE', 'COUNTRY', 'PHONE', 'DATE_MODIFIED'] |
17 | 18 |
18 if len(sys.argv) != 2: | 19 if len(sys.argv) != 2: |
19 print ("Usage: python reserialize_profiles_from_query.py " | 20 print ("Usage: python reserialize_profiles_from_query.py " |
20 "<path/to/serialized_profiles>") | 21 "<path/to/serialized_profiles>") |
21 return | 22 return |
22 | 23 |
23 types = [ColumnNameToFieldType(column_name) for column_name in COLUMNS] | 24 types = [ColumnNameToFieldType(column_name) for column_name in COLUMNS] |
24 profiles = [] | 25 profiles = [] |
25 with open(sys.argv[1], 'r') as serialized_profiles: | 26 with open(sys.argv[1], 'r') as serialized_profiles: |
26 for line in serialized_profiles: | 27 for line in serialized_profiles: |
27 # trim the newline if present | 28 # trim the newline if present |
28 if line[-1] == '\n': | 29 if line[-1] == '\n': |
29 line = line[:-1] | 30 line = line[:-1] |
30 | 31 |
31 values = line.split("|") | 32 values = line.split("|") |
32 profiles.append(zip(types, values)) | 33 profiles.append(zip(types, values)) |
33 | 34 |
34 print SerializeProfiles(profiles) | 35 print SerializeProfiles(profiles) |
| 36 return 0 |
35 | 37 |
36 | 38 |
37 if __name__ == '__main__': | 39 if __name__ == '__main__': |
38 main() | 40 sys.exit(main()) |
OLD | NEW |