| 40 | |
| 41 | |
| 42 | def convert(src_path, dst_path): |
| 43 | try: |
| 44 | with open(src_path, "r") as f: |
| 45 | src = f.read() |
| 46 | except (OSError, IOError): |
| 47 | logging.error("Cannot read src file {}".format(src_path)) |
| 48 | return |
| 49 | |
| 50 | countries, mwms = deserialize_places(src) |
| 51 | |
| 52 | # Carcass of the result. |
| 53 | result = { |
| 54 | "enabled": {"countries": [], "mwms": []}, |
| 55 | "disabled": {"countries": [], "mwms": []} |
| 56 | } |
| 57 | |
| 58 | for country, cities in countries.iteritems(): |
| 59 | result["enabled"]["countries"].append({ |
| 60 | "id": country, |
| 61 | "cities": cities |
| 62 | }) |
| 63 | |
| 64 | result["enabled"]["mwms"] = mwms |
| 65 | |
| 66 | try: |
| 67 | with open(dst_path, "w") as f: |
| 68 | json.dump(result, f, indent=2, sort_keys=True) |
| 69 | except (OSError, IOError): |
| 70 | logging.error("Cannot write result into dst file {}".format(dst_path)) |
| 71 | return |
| 72 | |
| 73 | |
| 74 | def process_options(): |