-
Notifications
You must be signed in to change notification settings - Fork 676
Adds support for system-wide config file. #200
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
Conversation
mycli/config.py
Outdated
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.
Nice trick to avoid stomping on built-in file keyword.
|
Looks like you're targeting Python 3. There is no such thing called |
|
I was surprised when you said it'll print the error messages at startup because I've never seen that behavior when loggers are uninitialized. Here's what I get when there is a parsing error in /etc/myclirc. |
|
It looks like, as of Python 3.2, logging writes to I think that most users expect command-line apps to write user-facing error messages to stderr. I'd hate for our Python 2 users to not see a potentially helpful error message. So, I suggest that we use the By the way, thanks for pointing out the |
Python 3 really makes it easy to do the right thing.
Yes!! I completely agree. We should make choices that are most intuitive for the user. So, let's use print statements there. |
mycli/config.py
Outdated
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.
Nice touch adding the line numbers. We might get some complaints regarding this error message since ConfigObj will fail on some of the constructs such as !includedir /usr/local/etc/my.cnf.d. But I think that is inevitable.
|
An interesting side effect of this change is now I'm aware of an inefficiency. I noticed that when I launched mycli I got the Optimizing that should help a little bit with startup time. :) |
|
Changes look good and it works without a hitch. I'm a bit hesitant about the parsing error being printed at startup. ConfigObj can't parse some of the INI file extension that might be valid for mysql but not valid for ConfigObj. So people can't change those lines to be ConfigObj compliant. This means we'll be printing that error message every time they start mycli. Which seems excessive. Since this is only an issue when we're reading my.cnf files, can we log those messages to the log file instead of stdout? This means, errors in RC files will be printed to stdout, but errors in my.cnf files will be logged to the log file. I can't think of a better solution. Suggestions welcome. |
|
@amjith I agree. I'll have
|
|
@amjith Ok, I've added those changes. There is some optimizing to reading config files that could be done, but this doesn't seem like the appropriate pull request for that. Let me know what you think of the changes. |
|
Looks good. 👍 You're right the optimization are a digression to this PR. We can do it on a different PR. |
Adds support for system-wide config file.
This fixes #161 by introducing system-wide config files. Right now, only
'/etc/myclirc'is checked, but adding other locations to the code is a simple as adding an item to a list. If the last successful file read is not a system-wide config file, then mycli checks to see if it should write the default user config file (by seeing if one exists). But, if the last successful file read was a system-wide config file, then no default user config file is created.This cleans up and refactors some of the
ConfigObj()code to use a generic function that handles two types of errors: config parsing errors and file permission errors.Because logging isn't initialized before we read the config files, these two outputs are possible:
And:
I'm not sure if there is a better way to deal with those messages. They aren't printed by
mycli.pyso they don't know aboutclick.secho(). They are basic logging calls to the default logging handler (stderr). Can anyone think of a better way to handle this? Or are we happy with it as it is?