comparison lxmldump.py @ 21:7ef08e05a5bf

Cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 May 2021 18:37:53 +0300
parents f274504eafd0
children 76856fc4e5fa
comparison
equal deleted inserted replaced
20:f274504eafd0 21:7ef08e05a5bf
36 "hanjahtoakseh", 36 "hanjahtoakseh",
37 "akkalisto", 37 "akkalisto",
38 ] 38 ]
39 39
40 40
41 # Operation modes
42 PKK_MODE_NORMAL = 0
43 PKK_MODE_DUMP = 1
44 PKK_MODE_XML = 2
45
46
41 ### 47 ###
42 ### Misc. helper functions, etc 48 ### Misc. helper functions, etc
43 ### 49 ###
44 def pkk_cleanup(): 50 def pkk_cleanup():
45 return 0 51 return 0
214 220
215 optparser.add_argument("filenames", action="extend", nargs="*", 221 optparser.add_argument("filenames", action="extend", nargs="*",
216 type=str, metavar="filename", help="XML filename(s)") 222 type=str, metavar="filename", help="XML filename(s)")
217 223
218 optparser.add_argument("-d", "--dump", 224 optparser.add_argument("-d", "--dump",
219 action="store_const", const=1, default=0, 225 action="store_const", const=PKK_MODE_DUMP, default=PKK_MODE_NORMAL,
220 dest="mode", help="output as simple dump") 226 dest="mode", help="output as simple dump")
221 227
222 optparser.add_argument("-x", "--xml", 228 optparser.add_argument("-x", "--xml",
223 action="store_const", const=2, 229 action="store_const", const=PKK_MODE_XML,
224 dest="mode", help="output as XML") 230 dest="mode", help="output as XML")
225 231
226 optparser.add_argument("-n", "--normalize", 232 optparser.add_argument("-n", "--normalize",
227 action="store_const", const=True, default=False, 233 action="store_const", const=True, default=False,
228 dest="normalize", help="output NFC normalized Unicode") 234 dest="normalize", help="output NFC normalized Unicode")
262 for dnode in xroot.findall("./DictionaryEntry"): 268 for dnode in xroot.findall("./DictionaryEntry"):
263 269
264 if pkk_cfg.debug and dnode.attrib["identifier"] not in pkk_debug_list: 270 if pkk_cfg.debug and dnode.attrib["identifier"] not in pkk_debug_list:
265 continue 271 continue
266 272
267 if pkk_cfg.mode == 0: 273 if pkk_cfg.mode == PKK_MODE_NORMAL:
268 try: 274 try:
269 pkk_output_node(0, dnode) 275 pkk_output_node(0, dnode)
270 except Exception as e: 276 except Exception as e:
271 pkk_dump_recursive(0, dnode) 277 pkk_dump_recursive(0, dnode)
272 print(str(e)) 278 print(str(e))
273 sys.exit(0) 279 sys.exit(0)
274 elif pkk_cfg.mode == 1: 280 elif pkk_cfg.mode == PKK_MODE_DUMP:
275 pkk_dump_recursive(0, dnode) 281 pkk_dump_recursive(0, dnode)
276 elif pkk_cfg.mode == 2: 282 elif pkk_cfg.mode == PKK_MODE_XML:
277 pkk_print(str(xmlET.tostring(dnode, encoding="utf8")) + "\n") 283 pkk_print(str(xmlET.tostring(dnode, encoding="utf8")) + "\n")
278 else: 284 else:
279 pkk_fatal("Invalid operation mode?") 285 pkk_fatal("Invalid operation mode?")
280 286
281 print("\n") 287 print("\n")