-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added a simple config parser and updated argument defaults * Fixed import sorting * Update changelog * Added configuration instructions to the readme * Added logging level to configuration file * Fixed import sorting
- Loading branch information
1 parent
0a63360
commit 9991906
Showing
6 changed files
with
111 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import logging | ||
|
||
from .config import get_config | ||
|
||
logging.basicConfig( | ||
level=logging.DEBUG, format="%(asctime)s %(levelname)7s : %(name)s : %(message)s" | ||
level=get_config().get("logging", "level").upper(), | ||
format="%(asctime)s %(levelname)8s : %(name)s -> %(message)s", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import configparser | ||
import os.path | ||
|
||
__DEFAULTS_CONNECTION = { | ||
"host": "localhost", | ||
"port": 6600, | ||
} | ||
|
||
__DEFAULTS_LOGGING = { | ||
"level": "info", | ||
} | ||
|
||
__DEFAULTS_BINDS = { | ||
"refresh": "r", | ||
} | ||
|
||
__CONFIG = None | ||
|
||
|
||
def get_config(): | ||
""" | ||
Read configuration from a file. | ||
""" | ||
|
||
global __CONFIG | ||
|
||
if __CONFIG is not None: | ||
return __CONFIG | ||
|
||
config = configparser.ConfigParser() | ||
|
||
# Load default settings. | ||
config.read_dict({"connection": __DEFAULTS_CONNECTION}) | ||
config.read_dict({"logging": __DEFAULTS_LOGGING}) | ||
config.read_dict({"binds": __DEFAULTS_BINDS}) | ||
|
||
# Read user settings from a file. | ||
config.read(os.path.expanduser(os.path.join("~", ".mpcover.ini"))) | ||
|
||
__CONFIG = config | ||
|
||
return config | ||
|
||
|
||
__all__ = "get_config" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters