2 This is ostensibly the place where Scripts specific code should live.
14 from wizard import shell, util
18 homedir, _, web_path = dir.partition("/web_scripts")
20 yield urlparse.ParseResult(
22 util.get_dir_owner(homedir) + ".scripts.mit.edu",
25 yield urlparse.ParseResult(
28 "/~" + util.get_dir_owner(homedir) + web_path.rstrip('/'),
31 logging.info("Directory location did not contain web_scripts: %s", dir)
33 def user_quota(dir=None):
35 Returns a tuple (quota usage, quota limit). Works only for scripts
36 servers. Values are in KiB. Returns ``(0, None)`` if we couldn't figure it out.
39 # sometimes the volume is busy; so we try several times
40 for i in range(0, end + 1):
42 return _user_quota(dir)
43 except QuotaParseError as e:
46 time.sleep(3) # give it a chance to unbusy
47 assert False # should not get here
49 def _user_quota(dir=None):
50 # XXX: The correct way is to implement Python modules implementing
51 # bindings for all the appropriate interfaces
53 def parse_last_quote(ret):
54 return ret.rstrip('\'').rpartition('\'')[2]
59 cell = parse_last_quote(sh.eval("fs", "whichcell", "-path", dir))
60 except shell.CallError:
63 if e.errno == errno.ENOENT:
69 volume = parse_last_quote(sh.eval("fs", "lsmount", dir))[1:]
71 except shell.CallError:
72 dir = os.path.dirname(dir)
74 if e.errno == errno.ENOENT:
77 if not volume: return unknown
79 result = sh.eval("vos", "examine", "-id", volume, "-cell", cell).splitlines()
82 result = sh.eval("/usr/sbin/vos", "examine", "-id", volume, "-cell", cell).splitlines()
85 except shell.CallError:
88 usage = int(result[0].split()[3])
89 limit = int(result[3].split()[1]) # XXX: FRAGILE
91 raise QuotaParseError("vos examine output was:\n\n" + "\n".join(result))
94 class QuotaParseError(wizard.Error):
95 """Could not parse quota information."""
96 def __init__(self, msg):
101 ERROR: Could not parse quota. %s
105 if url.driver == "mysql":
107 url.host, url.username, url.password = shell.Shell().eval("/mit/scripts/sql/bin/get-password").split()
109 except shell.CallError: