1 # -*- coding: utf-8 -*-
3 from __future__
import absolute_import
7 from jben
import configure
8 import jblite
.kd2
, jblite
.jmdict
11 class DictManager(object):
13 """Dictionary manager class."""
15 def __init__(self
, app
):
21 def get_dict_directory(self
):
22 return configure
.get_datadir()
24 def find_databases(self
):
25 datadir
= self
.get_dict_directory()
27 kd2_path
= os
.path
.join(datadir
, "kd2.db")
28 if os
.path
.exists(kd2_path
):
29 # Load an existing database.
30 self
.kd2
= jblite
.kd2
.Database(kd2_path
)
32 # Try to create the database.
33 kd2_xml_path
= os
.path
.join(datadir
, "kanjidic2.xml.gz")
34 if os
.path
.exists(kd2_xml_path
):
35 print "Creating KANJIDIC2 SQLite database; please wait..."
36 self
.kd2
= jblite
.kd2
.Database(kd2_path
,
37 init_from_file
=kd2_xml_path
)
41 jmdict_path
= os
.path
.join(datadir
, "jmdict.db")
42 if os
.path
.exists(jmdict_path
):
43 self
.jmdict
= jblite
.jmdict
.Database(jmdict_path
)
45 jmdict_xml_path
= os
.path
.join(datadir
, "JMdict.gz")
46 if os
.path
.exists(jmdict_xml_path
):
47 print "Creating JMdict SQLite database; please wait..."
48 self
.jmdict
= jblite
.jmdict
.Database(
49 jmdict_path
, init_from_file
=jmdict_xml_path
)
53 def all_dicts_found(self
):
54 return (self
.kd2
is not None) and (self
.jmdict
is not None)
56 def jmdict_found(self
):
57 return (self
.jmdict
is not None)
60 return (self
.kd2
is not None)
62 def get_needed_dict_names(self
):
63 """Returns a list of file names of any missing dictionary files."""
65 if not self
.kd2_found():
66 needed
.append("kanjidic2.xml.gz")
67 if not self
.jmdict_found():
68 needed
.append("JMdict.gz")