8 from wizard import shell, util
10 def fill_url(dir, url=None):
17 homedir, _, web_path = dir.partition("/web_scripts")
19 return urlparse.ParseResult(
21 util.get_dir_owner(homedir) + ".scripts.mit.edu",
26 host = os.getenv("WIZARD_WEB_HOST")
27 path = os.getenv("WIZARD_WEB_PATH")
28 if host is not None and path is not None:
29 return urlparse.ParseResult(
37 def get_quota_usage_and_limit(dir=None):
39 Returns a tuple (quota usage, quota limit). Works only for scripts
40 servers. Values are in KiB. Returns ``(0, None)`` if we couldn't figure it out.
42 # XXX: The correct way is to implement Python modules implementing
43 # bindings for all the appropriate interfaces
44 def parse_last_quote(ret):
45 return ret.rstrip('\'').rpartition('\'')[2]
50 cell = parse_last_quote(sh.eval("fs", "whichcell", "-path", dir))
51 except shell.CallError:
54 if e.errno == errno.ENOENT:
60 volume = parse_last_quote(sh.eval("fs", "lsmount", dir))[1:]
62 except shell.CallError:
63 dir = os.path.dirname(dir)
65 if e.errno == errno.ENOENT:
68 if not volume: return (0, None)
70 result = sh.eval("vos", "examine", "-id", volume, "-cell", cell).splitlines()
73 result = sh.eval("/usr/sbin/vos", "examine", "-id", volume, "-cell", cell).splitlines()
76 except shell.CallError:
79 usage = int(result[0].split()[3])
80 limit = int(result[3].split()[1]) # XXX: FRAGILE
82 raise QuotaParseError("vos examine output was:\n\n" + "\n".join(result))
85 # XXX: Possibly in the wrong module
86 def get_disk_usage(dir=None, excluded_dir=".git"):
88 Recursively determines the disk usage of a directory, excluding
89 .git directories. Value is in bytes.
91 if dir is None: dir = os.getcwd()
93 for root, _, files in os.walk(dir):
95 if not os.path.join(root, name).startswith(dir + excluded_dir):
96 sum_sizes += os.path.getsize(os.path.join(root, name))
98 class QuotaParseError(wizard.Error):
99 def __init__(self, msg):
104 ERROR: Could not parse quota. %s