geophysics/MTpy — pull request #8 by nietky (2012-10-10 02:01:45+00:00)
Title: Add configuration module for MTpy

Implement persistent configuration settings in INI files

I've done this as a way to begin tackling all the hardcoded paths that are everywhere. So far there are no settings in ``MTpy.ini``, just a framework for setting them -- see below.

The name/value pair settings are kept in section groups in a SafeConfigParser object which you can get by doing:

>>> from MTpy.config import config

For more information on this object see:

http://docs.python.org/library/configparser.html
http://www.doughellmann.com/PyMOTW/ConfigParser/#accessing-configuration-settings

---

The module attempts to load settings from files in four locations, in this order:

1. Github, but only if necessary
2. $SOURCEFOLDER/MTpy/MTpy.ini
3. $HOME/MTpy.ini
4. ./MTpy.ini

Settings found in later files override those in earlier files, meaning that the user
can set individual settings per directory, or per user, and the defaults are read
from the system's file. An attempt is made to download from Github only if no
INI files can be found locally at all.