foss2serve / corral-dev

Development effort for Corral
GNU General Public License v3.0
0 stars 1 forks source link

Handling configuration and avoid prompting #6

Open StoneyJackson opened 8 years ago

StoneyJackson commented 8 years ago

This program will have to run without prompting for anything. So you'll want a configuration file. Then whoever installs the system will just edit these files.

The easiest way to do this to add a python module for configuration: config.py.

DATA_ROOT = 'path/to/where/we/should/store/data'
GITHUB_ROOT = 'https://api.github.com'
GITHUB_USERNAME = 'Your Username'
GITHUB_PASSWORD = 'Your Password'

The problem (as you have discovered) is that this file contains information that we don't want stored in our repository. So store a file called config-example.py with sample and default definitions (like the example above), and then add instructions in README.md to copy this file to config.py and update config.py with appropriate values. Now you can tell git to ignore config.py while keeping config-example.py, by adding the following to a .gitignore file:

config.py

To use these values in your program, just import config and use the values.

## filename: main.py
import config
credentials = (config.GITHUB_USERNAME, config.GITHUB_PASSWORD)