1# http://stackoverflow.com/questions/15069127/python-configparser-module-\
2# rename-a-section
3def rename_section(cp, section_from, section_to):
4    items = cp.items(section_from)
5    cp.add_section(section_to)
6    for item in items:
7        cp.set(section_to, item[0], item[1])
8    cp.remove_section(section_from)
9
10# Checkpoint version F renames an internal member of Process class.
11def upgrader(cpt):
12    import re
13    for sec in cpt.sections():
14        fdm = 'FdMap'
15        fde = 'FDEntry'
16        if re.match('.*\.%s.*' % fdm, sec):
17            rename = re.sub(fdm, fde, sec)
18            split = re.split(fde, rename)
19
20            # rename the section and add the 'mode' field
21            rename_section(cpt, sec, rename)
22            cpt.set(rename, 'mode', "0") # no proper value to set :(
23
24            # add in entries 257 to 1023
25            if split[1] == "0":
26                for x in range(257, 1024):
27                    seq = (split[0], fde, "%s" % x)
28                    section = "".join(seq)
29                    cpt.add_section(section)
30                    cpt.set(section, 'fd', '-1')
31
32legacy_version = 15
33