4 def get_exception_name(output):
5 """Reads the stderr output of another Python command and grabs the
6 fully qualified exception name"""
7 lines = output.split("\n")
8 for line in lines[1:]: # skip the "traceback" line
10 if line[0] == ' ': continue
16 def get_dir_user(dir):
17 """Finds the username of the person who owns this directory, via LDAP.
18 Only works for directories under web_scripts"""
19 dir = os.path.realpath(dir)
20 homedir, _, _ = dir.partition("/web_scripts")
21 if homedir == dir: return None
22 con = ldap.initialize('ldap://scripts.mit.edu')
24 "ou=People,dc=scripts,dc=mit,dc=edu", # base
25 ldap.SCOPE_SUBTREE, # default
26 "homeDirectory=" + homedir, # search
28 )[0][1]["uid"][0] # unwrap the result
31 """Finds the URL a path would correspond to in the filesystem"""
32 _, _, path = dir.partition("/web_scripts")
33 return "http://%s.scripts.mit.edu%s" % (get_dir_user(dir), path)