]> scripts.mit.edu Git - wizard.git/blob - wizard/scripts.py
9676b3482f8e57b3a0515aad69455c38a1ddb972
[wizard.git] / wizard / scripts.py
1 import os
2
3 from wizard import shell
4
5 def get_sql_credentials():
6     """
7     Attempts to determine a user's MySQL credentials.  They are
8     returned as a three-tuple (host, user, password).
9     """
10     sh = shell.Shell()
11     host = os.getenv("WIZARD_MYSQL_HOST")
12     user = os.getenv("WIZARD_MYSQL_USER")
13     password = os.getenv("WIZARD_MYSQL_PASSWORD")
14     if host is not None and user is not None and password is not None:
15         return (host, user, password)
16     try:
17         return sh.eval("/mit/scripts/sql/bin/get-password").split()
18     except CallError:
19         return None
20