Encode the ID map into the specified scripttype ('python' or 'javascript') in the specified file.
(id_map, filename, scripttype)
| 113 | id_map[id] = [ chapter_id, id_title ] |
| 114 | |
| 115 | def generate_map(id_map, filename, scripttype): |
| 116 | """Encode the ID map into the specified scripttype ('python' or |
| 117 | 'javascript') in the specified file.""" |
| 118 | |
| 119 | fp = open(filename, 'w') |
| 120 | |
| 121 | # Python and JS are extremely similar when the output is just a |
| 122 | # dictionary of lists of strings. |
| 123 | |
| 124 | if scripttype == 'javascript': |
| 125 | print('exports.xrefMap = {', file=fp) |
| 126 | else: |
| 127 | print('xrefMap = {', file=fp) |
| 128 | |
| 129 | # Sort keys so the can be compared between runs |
| 130 | for id in sorted(id_map): |
| 131 | print(f" '{id}' : [ '{id_map[id][0]}', '{id_map[id][1]}' ],", file=fp) |
| 132 | |
| 133 | print('}', file=fp) |
| 134 | |
| 135 | fp.close() |
| 136 | |
| 137 | if __name__ == '__main__': |
| 138 | parser = argparse.ArgumentParser() |
no test coverage detected