some improved verbosity on groups and missing devices

xkb
sezanzeb 4 years ago committed by sezanzeb
parent 6b43e66bdd
commit 3c8ba4d34a

@ -133,6 +133,10 @@ class KeycodeInjector:
# started once.
raise Exception('Please construct a new injector instead')
if self.device not in get_devices():
logger.error('Cannot inject for unknown device "%s"', self.device)
return
self._process = multiprocessing.Process(target=self._start_injecting)
self._process.start()
@ -279,7 +283,7 @@ class KeycodeInjector:
loop = asyncio.get_event_loop()
coroutines = []
logger.info('Starting injecting the mapping for %s', self.device)
logger.info('Starting injecting the mapping for "%s"', self.device)
paths = get_devices()[self.device]['paths']

@ -50,4 +50,6 @@ def can_read_devices():
if not is_in_input_group:
warn('input')
return is_root or (is_in_input_group and is_in_plugdev_group)
ok = is_root or (is_in_input_group and is_in_plugdev_group)
return ok, is_root, is_in_input_group, is_in_plugdev_group

@ -42,6 +42,7 @@ from keymapper.gtk.unsaved import unsaved_changes_dialog, GO_BACK
from keymapper.dev.reader import keycode_reader
from keymapper.daemon import get_dbus_interface
from keymapper.config import config
from keymapper.dev.permissions import can_read_devices
def gtk_iteration():
@ -110,9 +111,24 @@ class Window:
self.window = window
# if any of the next steps take a bit to complete, have the window
# already visible to make it look more responsive.
# already visible (without content) to make it look more responsive.
gtk_iteration()
ok, _, is_input, is_plugdev = can_read_devices()
if not ok:
missing_groups = []
if not is_input:
missing_groups.append('input')
if not is_plugdev:
missing_groups.append('plugdev')
if len(missing_groups) > 0:
self.get('status_bar').push(
CTX_ERROR,
f'You are not in the {" and ".join(missing_groups)} '
f'group{"s" if len(missing_groups) > 0 else ""}'
)
self.populate_devices()
self.select_newest_preset()

@ -19,7 +19,6 @@
# along with key-mapper. If not, see <https://www.gnu.org/licenses/>.
import os
import grp
import unittest
@ -40,7 +39,7 @@ class TestPermissions(unittest.TestCase):
self.gr_mem = []
grp.getgrnam = Grnam
self.assertFalse(can_read_devices())
self.assertFalse(can_read_devices()[0])
def test_can_access(self):
class Grnam:
@ -48,7 +47,7 @@ class TestPermissions(unittest.TestCase):
self.gr_mem = [USER]
grp.getgrnam = Grnam
self.assertTrue(can_read_devices())
self.assertTrue(can_read_devices()[0])
if __name__ == "__main__":

Loading…
Cancel
Save