Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyboard library requires root on GNU/Linux #35

Closed
mobusdorphin opened this issue Sep 29, 2019 · 3 comments
Closed

keyboard library requires root on GNU/Linux #35

mobusdorphin opened this issue Sep 29, 2019 · 3 comments

Comments

@mobusdorphin
Copy link

@mobusdorphin mobusdorphin commented Sep 29, 2019

Type:

  • bug
  • feature
  • enhancement
  • question

Environment:

  • OS: GNU/Linux

I'm going to open a PR to resolve the issue:

  • yes
  • no

Description:

It looks like the keyboard library requires root on GNU/Linux, when calling keyboard.add_hotkey from Clipthread.run(), it fails when checking for root. I'm not sure how things work inside of Anki, but prior to initializing it looks like there needs to be some sort of request for root in order to use the keyboard library (From the boppreh/keyboard readme: Works with Windows and Linux (requires sudo))

Caught exception:
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/midict.py", line 604, in run
    keyboard.add_hotkey('x', self.handleSentenceExport)
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/__init__.py", line 637, in add_hotkey
    _listener.start_if_necessary()
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/_generic.py", line 35, in start_if_necessary
    self.init()
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/__init__.py", line 194, in init
    _os_keyboard.init()
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/_nixkeyboard.py", line 113, in init
    build_device()
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/_nixkeyboard.py", line 109, in build_device
    ensure_root()
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/_nixcommon.py", line 174, in ensure_root
    raise ImportError('You must be root to use this library on linux.')
<class 'ImportError'>: You must be root to use this library on linux.
@mvf
Copy link

@mvf mvf commented Sep 29, 2019

This is the MIA Japanese Addon repo and not the right place to report issues with the MIA Dictionary addon. Anyhow, you could try this:

  1. Add your user to /dev/tty's group:
$ sudo usermod -a -G $(stat -c %G /dev/tty) $USER
  1. Log out and back in
  2. Open /home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/_nixcommon.py in your favorite editor, scroll all the way down and remove the root check:
def ensure_root():
-    if os.geteuid() != 0:
-        raise ImportError('You must be root to use this library on linux.')
+    pass
@mobusdorphin
Copy link
Author

@mobusdorphin mobusdorphin commented Oct 28, 2019

It looks like it actually was user Input (the group that owns /dev/input/*) that my user needed to be added to (though it's possible it could be both). I commented out the check for root, and it came up for a permission denied on /dev/input/event5. I added that group as well and that at least cleared the "Permission Denied" error, but it looks like there's a new error that we've run into where it is unable to map the 'C' key:

Caught exception:
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/midict.py", line 605, in run
    keyboard.add_hotkey('C', self.handleSystemSearch)
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/__init__.py", line 639, in add_hotkey
    steps = parse_hotkey_combinations(hotkey)
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/__init__.py", line 571, in parse_hotkey_combinations
    return tuple(tuple(combine_step(step)) for step in parse_hotkey(hotkey))
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/__init__.py", line 342, in parse_hotkey
    scan_codes = key_to_scan_codes(hotkey)
  File "/home/dad/.local/share/Anki2/addons21/MIADictionary/keyboard/__init__.py", line 322, in key_to_scan_codes
    raise ValueError('Key {} is not mapped to any known key.'.format(repr(key)), e)
<class 'ValueError'>: ("Key 'C' is not mapped to any known key.", None)

It looks like that's still an MIA Dictionary issue though, but I am not sure where to find that repo - is that elsewhere other than on github? I'd be happy to open up an issue on wherever that is hosted if it's not relevant here.

Thanks!

@LucasMIA
Copy link
Collaborator

@LucasMIA LucasMIA commented Feb 20, 2020

No longer should require root.

@LucasMIA LucasMIA closed this Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.