Merge pull request #239 from asergi/master

Add support for local conf file
This commit is contained in:
Nicolas Hennion 2013-04-03 08:09:04 -07:00
commit b36ade0dd7
5 changed files with 9 additions and 2 deletions

2
README
View File

@ -119,7 +119,7 @@ The default configuration file is under:
/etc/glances/glances.conf (Linux)
or
/usr/local/etc/glances.conf (*BSD and OS X)
/usr/local/etc/glances/glances.conf (*BSD and OS X)
To override the default configuration, you can copy the `glances.conf` file to
your `$XDG_CONFIG_HOME` directory (e.g. Linux):

View File

@ -119,7 +119,7 @@ The default configuration file is under:
/etc/glances/glances.conf (Linux)
or
/usr/local/etc/glances.conf (*BSD and OS X)
/usr/local/etc/glances/glances.conf (*BSD and OS X)
To override the default configuration, you can copy the `glances.conf` file to
your `$XDG_CONFIG_HOME` directory (e.g. Linux):

0
glances/conf/glances.conf Executable file → Normal file
View File

7
glances/glances.py Executable file → Normal file
View File

@ -197,20 +197,27 @@ class Config:
Get a list of config file paths, taking into account of the OS,
priority and location.
* running from source: /path/to/glances/glances/conf
* Linux: ~/.config/glances, /etc/glances
* BSD: ~/.config/glances, /usr/local/etc/glances
* Mac: ~/Library/Application Support/glances, /usr/local/etc/glances
The config file will be searched in the following order of priority:
* /path/to/file (via -C flag)
* /path/to/glances/glances/conf
* user's home directory (per-user settings)
* /etc directory (system-wide settings)
"""
base_path = os.path.dirname(os.path.abspath(__file__))
local_path = os.path.join(base_path, 'conf', self.filename)
paths = []
if self.location is not None:
paths.append(self.location)
if os.path.exists(local_path):
paths.append(local_path)
if is_Linux or is_BSD:
paths.append(os.path.join(
os.environ.get('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'),

0
glances/tests/test_glances.py Executable file → Normal file
View File