Fix warnings from pyflakes.
--- a/py/gadict_c5.py Mon Mar 28 00:31:52 2016 +0300
+++ b/py/gadict_c5.py Mon Mar 28 00:37:40 2016 +0300
@@ -1,94 +1,97 @@
+# -*- coding: utf-8 -*-
+"""dictd C5 format writer"""
-import gadict
import io
import sys
+import gadict
-finame = None
-foname = None
-if len(sys.argv) >= 2:
- finame = sys.argv[1]
-if len(sys.argv) >= 3:
- foname = sys.argv[2]
-fin = io.open(finame, mode='r', buffering=1, encoding="utf-8")
+FINAME = None
+FONAME = None
+if len(sys.argv) >= 2:
+ FINAME = sys.argv[1]
+if len(sys.argv) >= 3:
+ FONAME = sys.argv[2]
-parser = gadict.Parser()
+FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8")
+
+PARSER = gadict.Parser()
try:
- dom = parser.parse(fin)
+ DOM = PARSER.parse(FIN)
except gadict.ParseException as ex:
- sys.stdout.write("{:s}{:s}\n".format(finame, repr(ex)))
+ sys.stdout.write("{:s}{:s}\n".format(FINAME, repr(ex)))
if __debug__:
import traceback
traceback.print_exc()
exit(1)
finally:
- fin.close()
+ FIN.close()
-prelude = dom[0]
+PRELUDE = DOM[0]
-with open(foname+".name", "w") as f: # for dictfmt -s
- if prelude.name is not None:
- f.write(prelude.name)
+with open(FONAME+".name", "w") as f: # for dictfmt -s
+ if PRELUDE.name is not None:
+ f.write(PRELUDE.name)
f.write("\n")
-with open(foname+".url", "w") as f: # for dictfmt -u
- if len(prelude.urls) > 0:
- f.write(prelude.urls[0])
+with open(FONAME+".url", "w") as f: # for dictfmt -u
+ if len(PRELUDE.urls) > 0:
+ f.write(PRELUDE.urls[0])
f.write("\n")
-if foname is None:
- fout = sys.stdout
+if FONAME is None:
+ FOUT = sys.stdout
else:
- fout = open(foname, "w")
+ FOUT = open(FONAME, "w")
-if prelude.name is not None:
- fout.write("Dictionary name: ")
- fout.write(prelude.name)
- fout.write("\n\n")
-fout.write("Project URLs: ")
-fout.write(" , ".join(prelude.urls))
-fout.write("\n\n")
-fout.write("Project licenses: ")
-fout.write(", ".join(prelude.licences))
-fout.write("\n\n")
-fout.write(prelude.about)
-fout.write("\n")
+if PRELUDE.name is not None:
+ FOUT.write("Dictionary name: ")
+ FOUT.write(PRELUDE.name)
+ FOUT.write("\n\n")
+FOUT.write("Project URLs: ")
+FOUT.write(" , ".join(PRELUDE.urls))
+FOUT.write("\n\n")
+FOUT.write("Project licenses: ")
+FOUT.write(", ".join(PRELUDE.licences))
+FOUT.write("\n\n")
+FOUT.write(PRELUDE.about)
+FOUT.write("\n")
-for idx in range(1, len(dom)):
- article = dom[idx]
- fout.write("_____\n\n")
+for idx in range(1, len(DOM)):
+ article = DOM[idx]
+ FOUT.write("_____\n\n")
title = "; ".join(article[0].keys())
- fout.write(title)
- fout.write("\n\n")
+ FOUT.write(title)
+ FOUT.write("\n\n")
for (word, (pron, attrs)) in article[0].items():
if word == "approach":
- fout.write(str(article[0]))
- fout.write(" ")
- fout.write(word)
- fout.write("\n")
+ FOUT.write(str(article[0]))
+ FOUT.write(" ")
+ FOUT.write(word)
+ FOUT.write("\n")
if pron is not None:
- fout.write(" [")
- fout.write(pron)
- fout.write("]\n")
+ FOUT.write(" [")
+ FOUT.write(pron)
+ FOUT.write("]\n")
if len(attrs) > 0:
- fout.write(" ")
+ FOUT.write(" ")
l = list(attrs)
l.sort()
- fout.write(", ".join(l))
- fout.write("\n")
- fout.write("\n")
+ FOUT.write(", ".join(l))
+ FOUT.write("\n")
+ FOUT.write("\n")
for (pos, trs, exs) in article[1]:
- fout.write(" ")
+ FOUT.write(" ")
if pos is not None:
- fout.write("⟨")
- fout.write(pos)
- fout.write("⟩ ")
+ FOUT.write("⟨")
+ FOUT.write(pos)
+ FOUT.write("⟩ ")
for (lang, tr) in trs:
if lang == "ru":
- fout.write(tr)
+ FOUT.write(tr)
break
- fout.write("\n")
+ FOUT.write("\n")