4 from wizard import shell, util
6 def get_sql_credentials(vars=None):
8 Attempts to determine a user's MySQL credentials. They are
9 returned as a three-tuple (host, user, password).
12 host = os.getenv("WIZARD_MYSQL_HOST")
13 user = os.getenv("WIZARD_MYSQL_USER")
14 password = os.getenv("WIZARD_MYSQL_PASSWORD")
15 if host is not None and user is not None and password is not None:
16 return (host, user, password)
17 # XXX: this is very fragile
18 elif vars and "WIZARD_DBSERVER" in vars and "WIZARD_DBUSER" in vars and "WIZARD_DBPASSWORD" in vars:
19 return (shlex.split(vars[x])[0] for x in ("WIZARD_DBSERVER", "WIZARD_DBUSER", "WIZARD_DBPASSWORD"))
21 tuple = sh.eval("/mit/scripts/sql/bin/get-password").split()
28 def get_web_host_and_path(dir=None):
30 Attempts to determine webhost and path for the current directory
31 as it would be accessible from the web. Works only for scripts
32 servers. Returns a tuple web_host, web_path, or None if it failed.
34 # XXX: THIS CODE SUCKS
35 host = os.getenv("WIZARD_WEB_HOST")
36 path = os.getenv("WIZARD_WEB_PATH")
37 if host is not None and path is not None:
41 _, _, web_path = dir.partition("/web_scripts")
44 return (util.get_dir_owner(dir) + ".scripts.mit.edu", web_path)