| 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 def main(): | 8 def main(): |
| 8 """Converts a vertical serialization into a compact, horizontal serialization. | 9 """Converts a vertical serialization into a compact, horizontal serialization. |
| 9 | |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 COLUMNS = ['First name', 'Middle name', 'Last name', 'Email', 'Company name', | 12 COLUMNS = ['First name', 'Middle name', 'Last name', 'Email', 'Company name', |
| 13 'Address line 1', 'Address line 2', 'City', 'State', 'ZIP code', | 13 'Address line 1', 'Address line 2', 'City', 'State', 'ZIP code', |
| 14 'Country', 'Phone'] | 14 'Country', 'Phone'] |
| 15 | 15 |
| 16 if len(sys.argv) != 2: | 16 if len(sys.argv) != 2: |
| 17 print "Usage: python flatten.py <path/to/serialized_profiles>" | 17 print "Usage: python flatten.py <path/to/serialized_profiles>" |
| 18 return | 18 return |
| 19 | 19 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 column_widths = [] | 52 column_widths = [] |
| 53 for column in transposed: | 53 for column in transposed: |
| 54 widths = [len(value) for value in column] | 54 widths = [len(value) for value in column] |
| 55 column_widths.append(max(widths)) | 55 column_widths.append(max(widths)) |
| 56 column_formats = ["{0:<" + str(width) + "}" for width in column_widths] | 56 column_formats = ["{0:<" + str(width) + "}" for width in column_widths] |
| 57 | 57 |
| 58 for profile in profiles: | 58 for profile in profiles: |
| 59 profile_format = zip(column_formats, profile) | 59 profile_format = zip(column_formats, profile) |
| 60 profile = [format_.format(value) for (format_, value) in profile_format] | 60 profile = [format_.format(value) for (format_, value) in profile_format] |
| 61 print " | ".join(profile) | 61 print " | ".join(profile) |
| 62 return 0 |
| 62 | 63 |
| 63 | 64 |
| 64 if __name__ == '__main__': | 65 if __name__ == '__main__': |
| 65 main() | 66 sys.exit(main()) |
| OLD | NEW |