Mercurial > hg > lxmldump
comparison lxmldump.py @ 79:5c7913c838cb
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 01 Mar 2022 13:23:09 +0200 |
parents | 1e1d478f4845 |
children | 0d9303f30e68 |
comparison
equal
deleted
inserted
replaced
78:1e1d478f4845 | 79:5c7913c838cb |
---|---|
204 sys.exit(1) | 204 sys.exit(1) |
205 | 205 |
206 | 206 |
207 ## Handler for SIGINT signals | 207 ## Handler for SIGINT signals |
208 def pkk_signal_handler(signal, frame): | 208 def pkk_signal_handler(signal, frame): |
209 print(u"\nQuitting due to SIGINT / Ctrl+C!") | 209 print("\nQuitting due to SIGINT / Ctrl+C!") |
210 sys.exit(1) | 210 sys.exit(1) |
211 | 211 |
212 | 212 |
213 def pkk_arg_range(vstr, vmin, vmax): | 213 def pkk_arg_range(vstr, vmin, vmax): |
214 try: | 214 try: |
557 | 557 |
558 pkk_cfg = optparser.parse_args() | 558 pkk_cfg = optparser.parse_args() |
559 | 559 |
560 if pkk_cfg.list_values: | 560 if pkk_cfg.list_values: |
561 if pkk_cfg.mode in [PKK_MODE_NORMAL, PKK_MODE_ANKI]: | 561 if pkk_cfg.mode in [PKK_MODE_NORMAL, PKK_MODE_ANKI]: |
562 print(u"Available format strings and values (mode '{}'):".format( | 562 print("Available format strings and values (mode '{}'):".format( |
563 pkk_modes_list[pkk_cfg.mode])) | 563 pkk_modes_list[pkk_cfg.mode])) |
564 | 564 |
565 for mid in pkk_mode_defaults: | 565 for mid in pkk_mode_defaults: |
566 stmp = pkk_get_value(mid).replace("\\", "\\\\").replace("\n", "\\n") | 566 stmp = pkk_get_value(mid).replace("\\", "\\\\").replace("\n", "\\n") |
567 print(u" {:22s} : '{}'".format(mid, stmp)) | 567 print(" {mid:22s} : '{stmp}'") |
568 else: | 568 else: |
569 print(u"Mode '{}' does not use format strings.".format( | 569 print("Mode '{}' does not use format strings.".format( |
570 pkk_modes_list[pkk_cfg.mode])) | 570 pkk_modes_list[pkk_cfg.mode])) |
571 | 571 |
572 sys.exit(0) | 572 sys.exit(0) |
573 | 573 |
574 elif len(pkk_cfg.filenames) == 0: | 574 elif len(pkk_cfg.filenames) == 0: |
578 for filename in pkk_cfg.filenames: | 578 for filename in pkk_cfg.filenames: |
579 # Parse XML file into element tree | 579 # Parse XML file into element tree |
580 try: | 580 try: |
581 uxml = xmlET.parse(filename) | 581 uxml = xmlET.parse(filename) |
582 except Exception as e: | 582 except Exception as e: |
583 pkk_fatal(u"SVG/XML parsing failed: {0}".format(str(e))) | 583 pkk_fatal(f"SVG/XML parsing failed: {str(e)}") |
584 | 584 |
585 # Dump output | 585 # Dump output |
586 try: | 586 try: |
587 xroot = uxml.getroot() | 587 xroot = uxml.getroot() |
588 for dnode in xroot.findall("./DictionaryEntry"): | 588 for dnode in xroot.findall("./DictionaryEntry"): |
602 pkk_dump_recursive(0, dnode) | 602 pkk_dump_recursive(0, dnode) |
603 print("") | 603 print("") |
604 elif pkk_cfg.mode == PKK_MODE_XML: | 604 elif pkk_cfg.mode == PKK_MODE_XML: |
605 pkk_print(xmlET.tostring(dnode, encoding="utf8").decode("utf8") + "\n\n") | 605 pkk_print(xmlET.tostring(dnode, encoding="utf8").decode("utf8") + "\n\n") |
606 else: | 606 else: |
607 pkk_fatal("Invalid operation mode?") | 607 pkk_fatal(f"Invalid operation mode '{pkk_cfg.mode}'.") |
608 | 608 |
609 except (BrokenPipeError, IOError) as e: | 609 except (BrokenPipeError, IOError) as e: |
610 sys.stderr.close() | 610 sys.stderr.close() |
611 sys.exit(1) | 611 sys.exit(1) |