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

KeyError: 'other' when running randrctl dump #13

Closed
eddie-dunn opened this issue Jun 15, 2018 · 5 comments
Closed

KeyError: 'other' when running randrctl dump #13

eddie-dunn opened this issue Jun 15, 2018 · 5 comments

Comments

@eddie-dunn
Copy link

% randrctl dump -e home
WARNING No home directories found among ['/home/user/.config/randrctl', '/etc/randrctl/']
WARNING Creating home under /home/user/.config/randrctl
Traceback (most recent call last):
  File "/home/user/.local/bin/randrctl", line 11, in <module>
    main()
  File "/home/user/.local/bin/randrctl", line 7, in main
    Main().run()
  File "/home/user/.local/lib/python3.6/site-packages/randrctl/__main__.py", line 115, in run
    self.randrctl = factory.get_randrctl()
  File "/home/user/.local/lib/python3.6/site-packages/randrctl/ctl.py", line 274, in get_randrctl
    config = self._load_config_files()
  File "/home/user/.local/lib/python3.6/site-packages/randrctl/ctl.py", line 229, in _load_config_files
    yaml_files = [config_file for config_file in config_files[use] if config_file.endswith('yaml')]
KeyError: 'other'

In case it matters, I installed randrctl via pip like so:

pip3 install --user randrctl

Crash encountered in Ubuntu 18.04.

@koiuo
Copy link
Owner

koiuo commented Jun 15, 2018

Thanks for the report. As an immediate workaround, please do

mkdir -p ~/.config/randrctl
touch ~/.config/randrctl/randrctl.yaml

I'm not 100% but this likely fix the issue.

I'll look into the root cause this weekend.

@eddie-dunn
Copy link
Author

Unfortunately, creating an empty yaml file didn't work (randrctrl already creates the folder ~/.config/randrctl if it doesn't exist already).

I skimmed through the code, and it seems to assume that a key exists when it in reality doesn't here:
https://github.com/edio/randrctl/blob/master/randrctl/ctl.py#L229

The _configs method in the same class never seems to create the keys you are looking for, perhaps because self.homes isn't set correctly when I run it?

Either way, when you create the dict maybe you should define it as configs = { self.OTHER: [] } or something? Or just use config_files.get(use, ()) on lines 229 and 231?

I don't have time to test my suggestions right now, so I might be off, though.

@koiuo
Copy link
Owner

koiuo commented Jun 15, 2018

@eddie-dunn I haven't wrote this code and don't recall the details.

Eventually, I was going to refactor it and eliminate ini files support in favor of yaml (since we have yaml dependency anyway).

Seems that the time has come.

As I said, I'll look into the issue this weekend. In case if you have a fix or an idea how to improve things, feel free to create a PR. But I do understand that the code right now is not in the best shape, so probably a lot has to be rewritten entirely.

@koiuo koiuo closed this as completed in c64425c Jun 16, 2018
@koiuo
Copy link
Owner

koiuo commented Jun 16, 2018

@eddie-dunn
I made some re-factoring and it issue must have fixed the issue.
Please check if it works and please let me know if it doesn't.

Thanks again for reporting!

@eddie-dunn
Copy link
Author

@edio I can confirm that your refactoring patch fixed the problem. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants