Skip to content

Instantly share code, notes, and snippets.

@beaugunderson
Created October 3, 2013 23:32
Show Gist options
  • Save beaugunderson/6818731 to your computer and use it in GitHub Desktop.
Save beaugunderson/6818731 to your computer and use it in GitHub Desktop.
import os
from contextlib import contextmanager
from fabric.api import env, hide, local
@contextmanager
def mysql_password(database):
contents = """
[client]
user={}
password={}
""".format(database['USER'], database['PASSWORD'])
credentials_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'.credentials.tmp')
local('touch {}'.format(credentials_file))
local('chmod 600 {}'.format(credentials_file))
with hide('running'):
local('echo "{}" > {}'.format(contents, credentials_file))
env['credentials_file'] = credentials_file
try:
yield
finally:
local('rm {}'.format(credentials_file))
del env['credentials_file']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment