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 def user_quota(dir=None):
33 Returns a tuple (quota usage, quota limit). Works only for scripts
34 servers. Values are in KiB. Returns ``(0, None)`` if we couldn't figure it out.
37 # sometimes the volume is busy; so we try several times
38 for i in range(0, end + 1):
40 return _user_quota(dir)
41 except QuotaParseError as e:
44 time.sleep(3) # give it a chance to unbusy
45 assert False # should not get here
47 def _user_quota(dir=None):
48 # XXX: The correct way is to implement Python modules implementing
49 # bindings for all the appropriate interfaces
51 def parse_last_quote(ret):
52 return ret.rstrip('\'').rpartition('\'')[2]
57 cell = parse_last_quote(sh.eval("fs", "whichcell", "-path", dir))
58 except shell.CallError:
61 if e.errno == errno.ENOENT:
67 volume = parse_last_quote(sh.eval("fs", "lsmount", dir))[1:]
69 except shell.CallError:
70 dir = os.path.dirname(dir)
72 if e.errno == errno.ENOENT:
75 if not volume: return unknown
77 result = sh.eval("vos", "examine", "-id", volume, "-cell", cell).splitlines()
80 result = sh.eval("/usr/sbin/vos", "examine", "-id", volume, "-cell", cell).splitlines()
83 except shell.CallError:
86 usage = int(result[0].split()[3])
87 limit = int(result[3].split()[1]) # XXX: FRAGILE
89 raise QuotaParseError("vos examine output was:\n\n" + "\n".join(result))
92 class QuotaParseError(wizard.Error):
93 """Could not parse quota information."""
94 def __init__(self, msg):
99 ERROR: Could not parse quota. %s
103 if url.driver == "mysql":
105 url.host, url.username, url.password = shell.Shell().eval("/mit/scripts/sql/bin/get-password").split()
107 except shell.CallError: