Last active
September 28, 2016 06:59
-
-
Save izimbra/c61b83194e4d312997934dda3ba8fc61 to your computer and use it in GitHub Desktop.
Converts phone records between different versions of CUCM (tested with 10.5 and 11.0). 'source.csv' - phone records exported from initial CUCM, 'dest.csv' - phone record template exported from the new CUCM (should contain field names). Data from 'source.csv' is copied to 'dest.csv' with deprecated fields being deleted, and new fields left empty.…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src = open('source.csv', 'r') | |
dest = open('dest.csv', 'a+') | |
# 2 arrays to represent CUCM phone records | |
cucm10 = src.readline().rstrip().split(',') | |
cucm11 = dest.readline().rstrip().split(',') #map(lambda s: s.rstrip(), | |
# fields that were added in CUCM 11 | |
new = set(cucm11) - set(cucm10) | |
print 'File {0} has {1} fields'.format(src.name, len(cucm10)) | |
print 'File {0} has {1} fields ({2} new)'.format(dest.name, len(cucm11), len(new)) | |
# mapping between CUCM 11 fields and CUCM 10 indices, -1 if the field is new | |
cucm10_indices = map(lambda field: -1 if field in new else cucm10.index(field), | |
cucm11) | |
# delete eventual records in new format - we only want to migrate old records | |
dest.truncate() | |
# iterate through the old records | |
for line in src: | |
# construct phone record according to new format | |
old_record = line.rstrip().split(',') | |
new_record = map(lambda i: old_record[i] if i >= 0 else '', | |
cucm10_indices) | |
# write it to file | |
dest.write(','.join(new_record) + '\n') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment