| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Converts profile datasets to dictionary list for Autofill profiles. | 7 """Converts profile datasets to dictionary list for Autofill profiles. |
| 8 | 8 |
| 9 Used for test autofill.AutofillTest.testMergeDuplicateProfilesInAutofill. | 9 Used for test autofill.AutofillTest.testMergeDuplicateProfilesInAutofill. |
| 10 Can be used as a stand alone script with -h to print out help text by running: | 10 Can be used as a stand alone script with -h to print out help text by running: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 u'NAME_LAST', | 31 u'NAME_LAST', |
| 32 u'EMAIL_ADDRESS', | 32 u'EMAIL_ADDRESS', |
| 33 u'COMPANY_NAME', | 33 u'COMPANY_NAME', |
| 34 u'ADDRESS_HOME_LINE1', | 34 u'ADDRESS_HOME_LINE1', |
| 35 u'ADDRESS_HOME_LINE2', | 35 u'ADDRESS_HOME_LINE2', |
| 36 u'ADDRESS_HOME_CITY', | 36 u'ADDRESS_HOME_CITY', |
| 37 u'ADDRESS_HOME_STATE', | 37 u'ADDRESS_HOME_STATE', |
| 38 u'ADDRESS_HOME_ZIP', | 38 u'ADDRESS_HOME_ZIP', |
| 39 u'ADDRESS_HOME_COUNTRY', | 39 u'ADDRESS_HOME_COUNTRY', |
| 40 u'PHONE_HOME_WHOLE_NUMBER', | 40 u'PHONE_HOME_WHOLE_NUMBER', |
| 41 u'PHONE_FAX_WHOLE_NUMBER', | |
| 42 ] | 41 ] |
| 43 _record_length = len(_fields) | 42 _record_length = len(_fields) |
| 44 _output_pattern = u'{' | 43 _output_pattern = u'{' |
| 45 for key in _fields: | 44 for key in _fields: |
| 46 _output_pattern += u"u'%s': u'%%s', " % key | 45 _output_pattern += u"u'%s': u'%%s', " % key |
| 47 _output_pattern = _output_pattern[:-1] + '},' | 46 _output_pattern = _output_pattern[:-1] + '},' |
| 48 _re_single_quote = re.compile("'", re.UNICODE) | 47 _re_single_quote = re.compile("'", re.UNICODE) |
| 49 _logger = logging.getLogger(__name__) | 48 _logger = logging.getLogger(__name__) |
| 50 _logger.addHandler(_NullHandler()) | 49 _logger.addHandler(_NullHandler()) |
| 51 _log_handlers = {'StreamHandler': None} | 50 _log_handlers = {'StreamHandler': None} |
| 52 | 51 |
| 53 def __init__(self, input_filename, output_filename=None, | 52 def __init__(self, input_filename, output_filename=None, |
| 54 logging_level=None): | 53 logging_level=None): |
| 55 """Constructs a dataset converter object. | 54 """Constructs a dataset converter object. |
| 56 | 55 |
| 57 Full input pattern: | 56 Full input pattern: |
| 58 '(?P<NAME_FIRST>.*?)\|(?P<MIDDLE_NAME>.*?)\|(?P<NAME_LAST>.*?)\| | 57 '(?P<NAME_FIRST>.*?)\|(?P<MIDDLE_NAME>.*?)\|(?P<NAME_LAST>.*?)\| |
| 59 (?P<EMAIL_ADDRESS>.*?)\|(?P<COMPANY_NAME>.*?)\|(?P<ADDRESS_HOME_LINE1>.*?) | 58 (?P<EMAIL_ADDRESS>.*?)\|(?P<COMPANY_NAME>.*?)\|(?P<ADDRESS_HOME_LINE1>.*?) |
| 60 \|(?P<ADDRESS_HOME_LINE2>.*?)\|(?P<ADDRESS_HOME_CITY>.*?)\| | 59 \|(?P<ADDRESS_HOME_LINE2>.*?)\|(?P<ADDRESS_HOME_CITY>.*?)\| |
| 61 (?P<ADDRESS_HOME_STATE>.*?)\|(?P<ADDRESS_HOME_ZIP>.*?)\| | 60 (?P<ADDRESS_HOME_STATE>.*?)\|(?P<ADDRESS_HOME_ZIP>.*?)\| |
| 62 (?P<ADDRESS_HOME_COUNTRY>.*?)\| | 61 (?P<ADDRESS_HOME_COUNTRY>.*?)\|(?P<PHONE_HOME_WHOLE_NUMBER>.*?)$' |
| 63 (?P<PHONE_HOME_WHOLE_NUMBER>.*?)\|(?P<PHONE_FAX_WHOLE_NUMBER>.*?)$' | |
| 64 | 62 |
| 65 Full ouput pattern: | 63 Full ouput pattern: |
| 66 "{u'NAME_FIRST': u'%s', u'NAME_MIDDLE': u'%s', u'NAME_LAST': u'%s', | 64 "{u'NAME_FIRST': u'%s', u'NAME_MIDDLE': u'%s', u'NAME_LAST': u'%s', |
| 67 u'EMAIL_ADDRESS': u'%s', u'COMPANY_NAME': u'%s', u'ADDRESS_HOME_LINE1': | 65 u'EMAIL_ADDRESS': u'%s', u'COMPANY_NAME': u'%s', u'ADDRESS_HOME_LINE1': |
| 68 u'%s', u'ADDRESS_HOME_LINE2': u'%s', u'ADDRESS_HOME_CITY': u'%s', | 66 u'%s', u'ADDRESS_HOME_LINE2': u'%s', u'ADDRESS_HOME_CITY': u'%s', |
| 69 u'ADDRESS_HOME_STATE': u'%s', u'ADDRESS_HOME_ZIP': u'%s', | 67 u'ADDRESS_HOME_STATE': u'%s', u'ADDRESS_HOME_ZIP': u'%s', |
| 70 u'ADDRESS_HOME_COUNTRY': u'%s', u'PHONE_HOME_WHOLE_NUMBER': u'%s', | 68 u'ADDRESS_HOME_COUNTRY': u'%s', u'PHONE_HOME_WHOLE_NUMBER': u'%s',}," |
| 71 u'PHONE_FAX_WHOLE_NUMBER': u'%s',}," | |
| 72 | 69 |
| 73 Args: | 70 Args: |
| 74 input_filename: name and path of the input dataset. | 71 input_filename: name and path of the input dataset. |
| 75 output_filename: name and path of the converted file, default is none. | 72 output_filename: name and path of the converted file, default is none. |
| 76 logging_level: set verbosity levels, default is ERROR. | 73 logging_level: set verbosity levels, default is ERROR. |
| 77 | 74 |
| 78 Raises: | 75 Raises: |
| 79 IOError: error if input file does not exist. | 76 IOError: error if input file does not exist. |
| 80 """ | 77 """ |
| 81 if logging_level: | 78 if logging_level: |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 options.logging_level = logging.WARNING | 220 options.logging_level = logging.WARNING |
| 224 elif 'error' in options.logging_level.lower(): | 221 elif 'error' in options.logging_level.lower(): |
| 225 options.logging_level = logging.ERROR | 222 options.logging_level = logging.ERROR |
| 226 | 223 |
| 227 c = DatasetConverter(options.input_filename, options.output_filename, | 224 c = DatasetConverter(options.input_filename, options.output_filename, |
| 228 options.logging_level) | 225 options.logging_level) |
| 229 c.Convert() | 226 c.Convert() |
| 230 | 227 |
| 231 if __name__ == '__main__': | 228 if __name__ == '__main__': |
| 232 main() | 229 main() |
| OLD | NEW |