import dbus
languages = {
'0': 'EN',
'1': 'RU',
}
def main():
remote_bus = dbus.SessionBus()
# Check if kbdd is running.
system_service_list = remote_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus').ListNames()
kbdd_api_found = 0
for service in system_service_list:
if service == 'ru.gentoo.KbddService':
kbdd_api_found = 1
break
if not kbdd_api_found:
return -1
# Get kbdd dbus api
kbdd_service = remote_bus.get_object('ru.gentoo.KbddService', '/ru/gentoo/KbddService')
# Connect to kdbb.
answer = kbdd_service.getCurrentLayout()
return answer
if __name__ == "__main__":
result = main()
print(languages[unicode(result)])
import subprocess
import re
languages = {
'first': 'EN',
'second': 'RU',
}
regular_strings = {
'hexadecimal': {
'first': """\w{4,4}e\w{3,3}""",
'second': """\w{4,4}f\w{3,3}""",
},
'binary': {
'first': """\w{4,4}0\w{3,3}""",
'second': """\w{4,4}1\w{3,3}""",
},
"inetger": """/^-?\d(?:\d|_)*$/""",
"led_mask": """LED mask:\s\s\w{8,8}""",
}
data = subprocess.check_output(['xset', '-q'])
raw_list = []
for item in data.strip().splitlines():
if re.search(regular_strings['led_mask'], item):
raw_led_mask = re.search(regular_strings['led_mask'], item).group()
raw_list = raw_led_mask.split(':')
led_mask = raw_list[1].strip()
break
print led_mask
if not re.search(regular_strings['inetger'], led_mask):
cur_regular_strings = regular_strings['hexadecimal']
else:
cur_regular_strings = regular_strings['binary']
if re.search(cur_regular_strings['first'], led_mask):
print languages['first']
elif re.search(cur_regular_strings['second'], led_mask):
print languages['second']
<feed xmlns="http://www.ixtens.com/xml/mp/override/R1.1“ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“ xsi:schemaLocation=”http://www.ixtens.com/xml/mp/override/R1.1 http://support.ixtens.com/mp/R1.1/product/override.xsd">
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.ixtens.com/xml/mp/override/R1.1" xsi:schemaLocation="http://www.ixtens.com/xml/mp/override/R1.1 http://support.ixtens.com/mp/R1.1/product/override.xsd">