Created
October 3, 2013 23:32
-
-
Save beaugunderson/6818731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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