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