(This rule is also known as SPOT - Single Point Of Truth).
One good solution I find when some piece of information is very configurable and need to be shard with many different programs is to write a little script that prints the required value.
For example, say we need to decide what is the root directory for something. It can be either the debug version of a standard one.
The script rootdir.py will look something like:
from os import environIf you're using Python, you can just write from root import ROOT_DIR, however if you're using bash you can write ROOTDIR=`./root.py` and then use $ROOTDIR
from os.path import join
from getpass import getuser
if "DEBUG" in environ:
# Every user has his/her own test root directory
ROOT_DIR = join("/tmp", "testing", getuser())
else:
ROOT_DIR = "/usr/local/cool"
if __name__ == "__main__":
print ROOT_DIR
No comments:
Post a Comment