-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
Conversation
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.
There was a problem hiding this 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.
auto_cpufreq/core.py
Outdated
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@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. |
* 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 <[email protected]>
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
New behavior