Beispiel #1
0
class StardictService(LocalService):

    def __init__(self, dict_path):
        super(StardictService, self).__init__(dict_path)
        self.query_interval = 0.5
        self.builder = Dictionary(self.dict_path, in_memory=False)
        self.builder.get_header()

    @staticmethod
    def support(dict_path):
        return os.path.isfile(dict_path) and dict_path.lower().endswith('.ifo')

    @property
    def title(self):
        if config.use_filename or not self.builder.ifo.bookname:
            return os.path.splitext(os.path.basename(self.dict_path))[0]
        else:
            return self.builder.ifo.bookname.decode('utf-8')

    @export(u"default", 0)
    def fld_whole(self):
        self.builder.check_build()
        try:
            result = self.builder[self.word]
            result = result.strip()\
                .replace('\r\n', '<br />')\
                .replace('\r', '<br />')\
                .replace('\n', '<br />')
            return QueryResult(result=result)
        except KeyError:
            return QueryResult.default()
Beispiel #2
0
 def run(self):
     for path in self.paths:
         mw.progress.update(label="Index building...\n%s" %
                            os.path.basename(path))
         if path.endswith('.mdx'):
             IndexBuilder(path)
         if path.endswith('.idx') or path.endswith('.idx.gz'):
             Dictionary(path, in_memory=True)
Beispiel #3
0
 def index(self):
     self.builder = Dictionary(self.dict_path, in_memory=True)
Beispiel #4
0
 def __init__(self, dict_path):
     super(StardictService, self).__init__(dict_path)
     self.query_interval = 0.5
     self.builder = Dictionary(self.dict_path, in_memory=False)
     self.builder.get_header()
Beispiel #5
0
 def index(self):
     try:
         self.builder = Dictionary(self.dict_path, in_memory=False)
         return True if self.builder else False
     except:
         return False