I am trying to create a module to hold configurations for a Fabric file. This configuration file will hold project dependent settings, so I can use the same fabfile for all our projects.
I want the fabfile to look like this:
import config
from fabric.api import local
def deploy(env='staging'):
config.env = env
local("xcopy {project_dir} {deploy_target} /u /r /y".format(project_dir=config.project_dir,
deploy_target=config.deploy_target))
#Ok, this will be more involved than that, but it is enough to explain my problem
and the config file to look like this:
env = 'staging'
project_dir = r'c:\some\unimportant\path'
deploy_target = r'c:\some\target\path\based\on\{env}'.format(env=env)
So I can use:
fab deploy
or fab deploy:staging
to deploy to the staging environment and fab deploy:production
to deploy to the production environment.
What I am trying to figure out is how to update the variables in the module when the env variable gets changed.
I want my config file as simple as possible, ideally, just variable assignments, but I could live with a few functions if really required. There will be a lot of variables in the settings file so updating the values in a function, using the global keyword would look really ugly.