[ibus-pinyin] add ibus-pinyin data files detect scripts

Peng Wu pwu at fedoraproject.org
Wed Feb 15 05:30:21 UTC 2012


commit 285be00debbaf7129b9e02c13771f3fdbdbd4747
Author: Peng Wu <alexepico at gmail.com>
Date:   Wed Feb 15 13:27:20 2012 +0800

    add ibus-pinyin data files detect scripts

 ibus-engine-pinyin.py |  124 +++++++++++++++++++++++++++++++++++++++++++++++++
 pinyin.xml            |   18 +++++++
 2 files changed, 142 insertions(+), 0 deletions(-)
---
diff --git a/ibus-engine-pinyin.py b/ibus-engine-pinyin.py
new file mode 100644
index 0000000..618ba23
--- /dev/null
+++ b/ibus-engine-pinyin.py
@@ -0,0 +1,124 @@
+#!/usr/bin/python
+
+import os
+
+'''
+Generate the engines of the pinyin.xml on the fly.
+'''
+
+pinyin_engine = \
+'''
+		<engine>
+			<name>pinyin</name>
+			<language>zh_CN</language>
+			<license>GPL</license>
+			<author>Peng Huang &lt;shawn.p.huang at gmail.com&gt;
+BYVoid &lt;byvoid1 at gmail.com&gt;
+Peng Wu &lt;alexepico at gmail.com&gt;</author>
+			<icon>/usr/share/ibus-pinyin/icons/ibus-pinyin.svg</icon>
+			<layout>us</layout>
+			<longname>Pinyin</longname>
+			<description>Pinyin input method</description>
+			<rank>99</rank>
+                        <!-- <hotkeys>Control+space,Alt+grave,Alt+Release+Alt_R</hotkeys> -->
+                        <symbol>&#x4E2D;</symbol>
+		</engine>
+'''
+
+bopomofo_engine = \
+'''
+		<engine>
+			<name>bopomofo</name>
+			<language>zh_TW</language>
+			<license>GPL</license>
+			<author>BYVoid &lt;byvoid1 at gmail.com&gt;
+Peng Huang &lt;shawn.p.huang at gmail.com&gt;
+Peng Wu &lt;alexepico at gmail.com&gt;</author>
+			<icon>/usr/share/ibus-pinyin/icons/ibus-bopomofo.svg</icon>
+			<layout>us</layout>
+			<longname>Bopomofo</longname>
+			<description>Bopomofo input method</description>
+			<rank>98</rank>
+                        <!-- <hotkeys>Control+space,Alt+grave,Alt+Release+Alt_R</hotkeys> -->
+                        <symbol>&#x4E2D;</symbol>
+		</engine>
+'''
+
+libpinyin_engine = \
+'''
+		<engine>
+			<name>libpinyin</name>
+			<language>zh_CN</language>
+			<license>GPL</license>
+			<author>Peng Huang &lt;shawn.p.huang at gmail.com&gt;
+                        Peng Wu &lt;alexepico at gmail.com&gt;
+                        BYVoid &lt;byvoid1 at gmail.com&gt;
+                        </author>
+			<icon>/usr/share/ibus-pinyin/icons/ibus-pinyin.svg</icon>
+			<layout>us</layout>
+			<longname>Intelligent Pinyin</longname>
+			<description>Intelligent Pinyin input method</description>
+			<rank>99</rank>
+                        <!-- <hotkeys>Control+space,Alt+grave,Alt+Release+Alt_R</hotkeys> -->
+                        <symbol>&#x4E2D;</symbol>
+		</engine>
+'''
+
+libbopomofo_engine = \
+'''
+		<engine>
+			<name>libbopomofo</name>
+			<language>zh_CN</language>
+			<license>GPL</license>
+			<author>Peng Huang &lt;shawn.p.huang at gmail.com&gt;
+                        BYVoid &lt;byvoid1 at gmail.com&gt;
+                        Peng Wu &lt;alexepico at gmail.com&gt;
+                        </author>
+			<icon>/usr/share/ibus-pinyin/icons/ibus-pinyin.svg</icon>
+			<layout>us</layout>
+			<longname>Intelligent Bopomofo</longname>
+			<description>Intelligent Bopomofo input method</description>
+			<Rank>99</rank>
+                        <!-- <hotkeys>Control+space,Alt+grave,Alt+Release+Alt_R</hotkeys> -->
+                        <symbol>&#x4E2D;</symbol>
+		</engine>
+'''
+
+sqlite_path = "/usr/share/ibus-pinyin/db/"
+sqlite_files = ["android.db", "open-phrase.db"]
+
+libpinyin_path = "/usr/share/libpinyin/data/"
+libpinyin_files = ["bigram.db", "gb_char.bin", "gbk_char.bin", "phrase_index.bin", "pinyin_index.bin"]
+
+
+def check_sqlite():
+    try:
+        os.chdir(sqlite_path)
+    except OSError:
+        return False
+    for onefile in sqlite_files:
+        if os.access(onefile, os.R_OK):
+            return True
+    return False
+
+
+def check_libpinyin():
+    try:
+        os.chdir(libpinyin_path)
+    except OSError:
+        return False
+    for onefile in libpinyin_files:
+        if not os.access(onefile, os.R_OK):
+            return False
+    return True
+
+
+### main function ###
+if __name__ == "__main__":
+    print ("<engines>\n")
+    if check_sqlite():
+        print (pinyin_engine + bopomofo_engine)
+    if check_libpinyin():
+        print (libpinyin_engine + libbopomofo_engine)
+    print ("</engines>\n")
+
diff --git a/pinyin.xml b/pinyin.xml
new file mode 100644
index 0000000..033ad69
--- /dev/null
+++ b/pinyin.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- filename: pinyin.xml -->
+<component>
+	<name>org.freedesktop.IBus.Pinyin</name>
+	<description>Pinyin Component</description>
+	<exec>/usr/libexec/ibus-engine-pinyin --ibus</exec>
+	<version>1.4.0</version>
+	<author>Peng Huang &lt;shawn.p.huang at gmail.com&gt;</author>
+	<license>GPL</license>
+	<homepage>http://code.google.com/p/ibus</homepage>
+	<textdomain>ibus-pinyin</textdomain>
+        <observed-paths>
+                <path>/usr/share/ibus-pinyin/db/android.db</path>
+                <path>/usr/share/ibus-pinyin/db/open-phrase.db</path>
+                <path>/usr/share/libpinyin/data/</path>
+        </observed-paths>
+        <engines exec="/usr/libexec/ibus-engine-pinyin.py" />
+</component>


More information about the scm-commits mailing list