Debian Codegraph @

engine/test-gnome.py

raw
1 #!/usr/bin/python3
2 # vim:set fileencoding=utf-8 et sts=4 sw=4:
3 #
4 # ibus - Intelligent Input Bus for Linux / Unix OS
5 #
6 # Copyright © 2025 Takao Fujiwara <[email protected]>
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library. If not, see <http://www.gnu.org/licenses/>.
20
21 # Check gnome-shell/js/misc/keyboardManager.js
22
23 from gi import require_version as gi_require_version
24 gi_require_version('GnomeDesktop', '4.0')
25
26 from gi.repository import GnomeDesktop
27
28 import os, re, sys
29
30
31 class TestGnomeDesktop:
32 __srcdir = '.'
33 __option_debug = False
34 __simple_filename = 'simple.xml.in'
35 __denylist_filename = 'denylist.txt'
36 __xkb_info = None
37 __simple_contents = None
38 __denylist_lines = None
39
40 @classmethod
41 def parse_args(cls):
42 cls.__srcdir = os.path.dirname(sys.argv[0])
43 if cls.__srcdir == '':
44 cls.__srcdir = '.'
45 if len(sys.argv) > 1:
46 arg1 = sys.argv[1]
47 if arg1 == '--debug':
48 cls.__option_debug = True
49
50 def __init__(self):
51 self.__simple_filename = '%s/%s' % (self.__srcdir,
52 self.__simple_filename)
53 self.__denylist_filename = '%s/%s' % (self.__srcdir,
54 self.__denylist_filename)
55 self.__xkb_info = GnomeDesktop.XkbInfo()
56
57 def read_simple(self):
58 simple_file = open(self.__simple_filename)
59 self.__simple_contents = simple_file.read()
60 simple_file.close()
61
62 def read_denylist(self):
63 denylist_file = open(self.__denylist_filename)
64 self.__denylist_lines = denylist_file.readlines()
65 denylist_file.close()
66 l = []
67 for line in self.__denylist_lines:
68 line = line.rstrip()
69 if len(line) == 0:
70 continue
71 if not line.startswith('#'):
72 l.append(line)
73 self.__denylist_lines = l
74
75 def __check_known_issue_engine_name(self, desc):
76 reason = None
77 if desc == 'xkb:in:eng:eng':
78 wrong_desc = 'xkb:in:eng:en'
79 simple_res = re.search(wrong_desc, self.__simple_contents)
80 if simple_res != None:
81 reason = '# Info: xkeyboard-config 2.42 has incorrect %s ' \
82 "but it's fixed in 2.44" % wrong_desc
83 return reason
84
85 def test_simple_with_gnome(self):
86 errnum = 0
87 for layout_variant in self.__xkb_info.get_all_layouts():
88 languages = self.__xkb_info.get_languages_for_layout(layout_variant)
89 layouts = layout_variant.split('+')
90 if len(languages) == 0:
91 if self.__option_debug:
92 print('# Info: No language: %s' % layout_variant)
93 continue
94 if len(layouts) >= 2:
95 desc = 'xkb:%s:%s:%s' % (layouts[0], layouts[1], languages[0])
96 else:
97 desc = 'xkb:%s::%s' % (layouts[0], languages[0])
98 if self.__option_debug:
99 print('# Debug: Test', layout_variant, languages, desc)
100 simple_res = re.search(desc, self.__simple_contents)
101 if simple_res == None:
102 denylist_res = None
103 for line in self.__denylist_lines:
104 denylist_res = re.match(line, desc)
105 if denylist_res != None:
106 break
107 if denylist_res == None:
108 reason = self.__check_known_issue_engine_name(desc)
109 if reason != None:
110 if self.__option_debug:
111 print(reason)
112 else:
113 errnum = errnum + 1
114 print('# Error: not found: %s' % desc, file=sys.stderr)
115 elif self.__option_debug:
116 print('# Info: %s in denylist' % desc)
117 return errnum
118
119
120 def main():
121 TestGnomeDesktop.parse_args()
122 obj = TestGnomeDesktop()
123 obj.read_simple()
124 obj.read_denylist()
125 errnum = obj.test_simple_with_gnome()
126 if errnum == 0:
127 print('Succeeded.')
128 else:
129 print('Failed. %s errors found.' % errnum, file=sys.stderr)
130 sys.exit(1)
131
132 main()