--- /dev/null
+"""
+This is ostensibly the place where Scripts specific code should live.
+"""
+
+import os
+import shlex
+import errno
+import logging
+import urlparse
+import time
+import errno
+
+import wizard
+from wizard import shell, util
+
+def deploy_web()
+ # try the directory
+ homedir, _, web_path = dir.partition("/web_scripts")
+ if web_path:
+ yield urlparse.ParseResult(
+ "http",
+ util.get_dir_owner(homedir) + ".scripts.mit.edu",
+ web_path.rstrip('/'),
+ "", "", "")
+ yield urlparse.ParseResult(
+ "http",
+ "scripts.mit.edu",
+ "/~" + util.get_dir_owner(homedir) + web_path.rstrip('/'),
+ "", "", "")
+
+def user_quota(dir=None):
+ """
+ Returns a tuple (quota usage, quota limit). Works only for scripts
+ servers. Values are in KiB. Returns ``(0, None)`` if we couldn't figure it out.
+ """
+ end = 2
+ # sometimes the volume is busy; so we try several times
+ for i in range(0, end + 1):
+ try:
+ return _user_quota(dir)
+ except QuotaParseError as e:
+ if i == end:
+ raise e
+ time.sleep(3) # give it a chance to unbusy
+ assert False # should not get here
+
+def _user_quota(dir=None):
+ # XXX: The correct way is to implement Python modules implementing
+ # bindings for all the appropriate interfaces
+ unknown = (0, None)
+ def parse_last_quote(ret):
+ return ret.rstrip('\'').rpartition('\'')[2]
+ if dir is None:
+ dir = os.getcwd()
+ sh = shell.Shell()
+ try:
+ cell = parse_last_quote(sh.eval("fs", "whichcell", "-path", dir))
+ except shell.CallError:
+ return unknown
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ return unknown
+ raise
+ mount = None
+ while dir:
+ try:
+ volume = parse_last_quote(sh.eval("fs", "lsmount", dir))[1:]
+ break
+ except shell.CallError:
+ dir = os.path.dirname(dir)
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ return unknown
+ raise
+ if not volume: return unknown
+ try:
+ result = sh.eval("vos", "examine", "-id", volume, "-cell", cell).splitlines()
+ except OSError:
+ try:
+ result = sh.eval("/usr/sbin/vos", "examine", "-id", volume, "-cell", cell).splitlines()
+ except OSError:
+ return unknown
+ except shell.CallError:
+ return unknown
+ try:
+ usage = int(result[0].split()[3])
+ limit = int(result[3].split()[1]) # XXX: FRAGILE
+ except ValueError:
+ raise QuotaParseError("vos examine output was:\n\n" + "\n".join(result))
+ return (usage, limit)
+
+class QuotaParseError(wizard.Error):
+ """Could not parse quota information."""
+ def __init__(self, msg):
+ self.msg = msg
+ def __str__(self):
+ return """
+
+ERROR: Could not parse quota. %s
+""" % self.msg