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

Add load from user config in XDG_CONFIG_HOME if available #672

Merged
merged 5 commits into from
Apr 3, 2024

Conversation

braun-steven
Copy link
Contributor

This update introduces the flexibility to load the configuration file from multiple locations, prioritizing user preferences and system standards. Previously, the configuration was strictly read from a hardcoded system path (/etc/auto-cpufreq.conf). Now, the application first checks if the user has specified a configuration file path via command line arguments. If not, it looks for a configuration file in the user's config directory ($XDG_CONFIG_HOME/auto-cpufreq/auto-cpufreq.conf). If neither is found, it defaults to the original system-wide configuration file.

This allows users to add their auto-cpufreq configuration to their dotfiles.

In addition, since providing a config file path via --config is now an explicit choice, an error is raised if this path is not a valid file.

Old behavior

auto-cpufreq --stats # Looks for config in "/etc/auto-cpufreq.conf"
auto-cpufreq --config <CONFIG> --stats # Looks for config in <CONFIG>
auto-cpufreq --config <INVALID_PATH> --stats  # No error/warning

New behavior

auto-cpufreq --stats # Looks for config in (A) "$XDG_CONFIG_HOME/auto-cpufreq/auto-cpufreq.conf" then (B) "/etc/auto-cpufreq.conf"
auto-cpufreq --config <CONFIG> --stats # Looks for config in <CONFIG>
auto-cpufreq --config <INVALID_PATH> --stats  # Error

This update introduces the flexibility to load the configuration file from
multiple locations, prioritizing user preferences and system standards.
Previously, the configuration was strictly read from a hardcoded
system path (`/etc/auto-cpufreq.conf`). Now, the application first checks if the
user has specified a configuration file path via command line arguments. If not,
it looks for a configuration file in the user's config
directory (`$XDG_CONFIG_HOME/auto-cpufreq/auto-cpufreq.conf`). If neither is
found, it defaults to the original system-wide configuration file.

This allows users to add their auto-cpufreq configuration to their dotfiles.
@braun-steven braun-steven changed the title Add load from user config from in XDG_CONFIG_HOME if available Add load from user config in XDG_CONFIG_HOME if available Apr 2, 2024
Copy link
Collaborator

@shadeyg56 shadeyg56 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one small comment in the review. I think overall this is a good change, but the config implementation is currently being reworked in #663 so this PR is going to conflict with that. It might be best to merge this PR to a different branch and then I can handle the merge myself.

I'll let @AdnanHodzic leave his thoughts.

print(f"Config file specified with '--config {args_config_file}' not found.")
sys.exit(1)

if args_config_file and os.path.isfile(args_config_file): # (1) Command line argument
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.path.isfile(args_config_file) in line 113 is redundant since it would be caught by line 109

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merged the two conditions: 2b3e9d9

@AdnanHodzic
Copy link
Owner

It might be best to merge this PR to a different branch and then I can handle the merge myself.

@shadeyg56, yes let's do this. As I said in PM, I'm out traveling for work for next 2 weeks and don't have my personal laptop with me to test/look into this properly.

Hence please feel free to merge it if it makes sense to you.

@shadeyg56 shadeyg56 changed the base branch from master to config-conflict April 3, 2024 15:36
@shadeyg56
Copy link
Collaborator

Looks good! I'm merging this into the config-conflict branch and I will merge these changes into #663 so that all of it can be merged into master at the same time.

Thanks for your contribution. You'll be credited as part of the next release

@shadeyg56 shadeyg56 merged commit 4cdcf74 into AdnanHodzic:config-conflict Apr 3, 2024
2 checks passed
AdnanHodzic pushed a commit that referenced this pull request Apr 30, 2024
* add config.py and config_event_handler.py
also introduces the utils folder

* update config imports and variables

* add 'pyinotify' dependency

* config: check for changes using threading

* config: handle errors and new eventsx

* config: set_path even if file doesn't exist and make new ConfigParser on every update

* fix get_config call

* config: check for changes on moved file

* call notifier.start() manually to prevent hanging

* config: update comments

* battery: fix config imports

* config: fix config deletion detection

* Add load from user config in XDG_CONFIG_HOME if available (#672)

* Add load from user config from in XDG_CONFIG_HOME if available

This update introduces the flexibility to load the configuration file from
multiple locations, prioritizing user preferences and system standards.
Previously, the configuration was strictly read from a hardcoded
system path (`/etc/auto-cpufreq.conf`). Now, the application first checks if the
user has specified a configuration file path via command line arguments. If not,
it looks for a configuration file in the user's config
directory (`$XDG_CONFIG_HOME/auto-cpufreq/auto-cpufreq.conf`). If neither is
found, it defaults to the original system-wide configuration file.

This allows users to add their auto-cpufreq configuration to their dotfiles.

* If --config is set but invalid, exit with error

* Remove redundant empty string check on config file path

* Remove duplicate isfile check for config path

See also: #672 (comment)

* Update configuration options in README

See also: #672

* config: move find_config_file function and fix finding home directory

* auto_cpufreq: fix hanging on --daemon, --live, and --monitor

* swap pyinotify for patched version

---------

Co-authored-by: Steven Braun <steven.braun.mz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants