Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ AC_CONFIG_FILES([po/Makefile.in
engine/Makefile
engine/ibus-engine-table
engine/ibus-table-createdb
engine/ibus-table-updatedb
engine/table.xml.in
data/Makefile
icons/Makefile
Expand Down
1 change: 1 addition & 0 deletions engine/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ table.xml.in
ibus-engine-table
ibus-table-createdb
ibus-table-createdb.1
ibus-table-updatedb
*.pyc
4 changes: 3 additions & 1 deletion engine/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ engine_table_DATA = \
$(NULL)
engine_tabledir = $(datadir)/ibus-table/engine

bin_SCRIPTS = ibus-table-createdb
bin_SCRIPTS = ibus-table-createdb ibus-table-updatedb

libexec_SCRIPTS = ibus-engine-table

Expand All @@ -45,6 +45,7 @@ enginedir = $(datadir)/ibus/component

EXTRA_DIST = \
ibus-table-createdb.in \
ibus-table-updatedb.in \
ibus-engine-table.in \
table.xml.in \
$(SGML) \
Expand All @@ -56,6 +57,7 @@ CLEANFILES = \
*.pyo \
ibus-engine-table \
ibus-table-createdb \
ibus-table-updatedb \
table.xml \
$(NULL)

Expand Down
29 changes: 29 additions & 0 deletions engine/ibus-table-updatedb.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
# vim:set et sts=4 sw=4
#
# ibus-table - The Tables engine for IBus
#
# Copyright (c) 2008-2009 Yu Yuwei <acevery@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
datarootdir=@datarootdir@
datadir=@datadir@
export IBUS_TABLE_DATA_DIR=@datarootdir@
export IBUS_TABLE_BIN_PATH=@bindir@
exec @PYTHON@ @datarootdir@/ibus-table/engine/tabupdatedb.py $@
77 changes: 69 additions & 8 deletions engine/tabsqlitedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,56 @@ def generate_userdb_desc (self):
import traceback
traceback.print_exc ()

def generate_sysdb_tabkeys(self):
db = self.db
if 'tabkeys' not in self.get_columns_of_phrase_table(db):
db.execute('ALTER TABLE phrases ADD COLUMN tabkeys TEXT;')
db.commit()

result = db.execute('SELECT count(*) FROM phrases WHERE ifnull(tabkeys, "") = ""').fetchall()
if result and result[0][0] == 0:
return

tab_dict = {
'a':1, 'b':2, 'c':3, 'd':4, 'e':5,
'f':6, 'g':7, 'h':8, 'i':9, 'j':10,
'k':11, 'l':12, 'm':13, 'n':14, 'o':15,
'p':16, 'q':17, 'r':18, 's':19, 't':20,
'u':21, 'v':22, 'w':23, 'x':24, 'y':25,
'z':26, "'":27, ';':28, '`':29, '~':30,
'!':31, '@':32, '#':33, '$':34, '%':35,
'^':36, '&':37, '*':38, '(':39, ')':40,
'-':41, '_':42, '=':43, '+':44, '[':45,
']':46, '{':47, '}':48, '|':49, '/':50,
':':51, '"':52, '<':53, '>':54, ',':55,
'.':56, '?':57, '\\':58, 'A':59, 'B':60,
'C':61, 'D':62, 'E':63, 'F':64, 'G':65,
'H':66, 'I':67, 'J':68, 'K':69, 'L':70,
'M':71, 'N':72, 'O':73, 'P':74, 'Q':75,
'R':76, 'S':77, 'T':78, 'U':79, 'V':80,
'W':81, 'X':82, 'Y':83, 'Z':84, '0':85,
'1':86, '2':87, '3':88, '4':89, '5':90,
'6':91, '7':92, '8':93, '9':94,
# for translit
u'ä':95,
u'ö':96,
u'ü':97,
u'Ä':98,
u'Ö':99,
u'Ü':100
}
id_tab_dict = {}
for key, id in tab_dict.items():
id_tab_dict[id] = key

def concat_chars(*args):
chars = [id_tab_dict.get(id, '') for id in args]
return ''.join(chars)

db.create_function('concat_chars', 5, concat_chars)
db.execute('UPDATE phrases set tabkeys = concat_chars(m0,m1,m2,m3,m4);')
db.commit()

def init_user_db(self,db_file):
if not path.exists(db_file):
db = sqlite3.connect(db_file)
Expand Down Expand Up @@ -894,12 +944,12 @@ def get_database_desc (self, db_file):
except:
return None

def get_number_of_columns_of_phrase_table(self, db_file):
def get_columns_of_phrase_table(self, db):
'''
Get the number of columns in the 'phrases' table in
Get the column names of the 'phrases' table in
the database in db_file.

Determines the number of columns by parsing this:
Determined by parsing this:

sqlite> select sql from sqlite_master where name='phrases';
CREATE TABLE phrases
Expand All @@ -910,10 +960,7 @@ def get_number_of_columns_of_phrase_table(self, db_file):
This result could be on a single line, as above, or on multiple
lines.
'''
if not path.exists (db_file):
return 0
try:
db = sqlite3.connect (db_file)
tp_res = db.execute(
"select sql from sqlite_master where name='phrases';"
).fetchall()
Expand All @@ -923,9 +970,23 @@ def get_number_of_columns_of_phrase_table(self, db_file):
res = re.match(r'.*\((.*)\)', str)
if res:
tp = res.group(1).split(',')
return len(tp)
names = [column.strip().split(' ')[0] for column in tp]
return names
else:
return 0
return []
except:
return []

def get_number_of_columns_of_phrase_table(self, db_file):
'''
Get the number of columns in the 'phrases' table in
the database in db_file.
'''
if not path.exists(db_file):
return 0
try:
db = sqlite3.connect(db_file)
return len(self.get_columns_of_phrase_table(db))
except:
return 0

Expand Down
66 changes: 66 additions & 0 deletions engine/tabupdatedb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# vim:et sts=4 sw=4
#
# ibus-table - The Tables engine for IBus
#
# Copyright (c) 2008-2009 Yu Yuwei <acevery@gmail.com>
# Copyright (c) 2009-2014 Caius "kaio" CHANCE <me@kaio.net>
# Copyright (c) 2012-2014 Mike FABIAN <mfabian@redhat.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#

import os
import sys
sys.path.append( os.path.dirname(os.path.abspath(__file__)) )
import tabsqlitedb

from optparse import OptionParser

# we use OptionParser to parse the cmd arguments :)
usage = "usage: %prog table.db"
opt_parser = OptionParser(usage=usage)

opt_parser.add_option( '-d', '--debug',
action = 'store_true', dest='debug', default = False,
help = 'Print extra debug messages.')

opts,args = opt_parser.parse_args()


def main():
def debug_print(message):
if opts.debug:
print(message)

db_path = args[0] if len(args) > 0 else None
if not db_path:
opt_parser.print_help()
print('\nYou need to specify the database file of the IME!')
sys.exit(2)

debug_print("Processing Database")
db = tabsqlitedb.tabsqlitedb(filename=db_path,
user_db=None,
create_database=False)

db.generate_sysdb_tabkeys()

debug_print('Done! :D')


if __name__ == "__main__":
main()