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.
43 # sometimes the volume is busy; so we try several times
46 return _get_quota_usage_and_limit(dir)
47 except QuotaParseError as e:
51 def _get_quota_usage_and_limit(dir=None):
52 # XXX: The correct way is to implement Python modules implementing
53 # bindings for all the appropriate interfaces
54 def parse_last_quote(ret):
55 return ret.rstrip('\'').rpartition('\'')[2]
60 cell = parse_last_quote(sh.eval("fs", "whichcell", "-path", dir))
61 except shell.CallError:
64 if e.errno == errno.ENOENT:
70 volume = parse_last_quote(sh.eval("fs", "lsmount", dir))[1:]
72 except shell.CallError:
73 dir = os.path.dirname(dir)
75 if e.errno == errno.ENOENT:
78 if not volume: return (0, None)
80 result = sh.eval("vos", "examine", "-id", volume, "-cell", cell).splitlines()
83 result = sh.eval("/usr/sbin/vos", "examine", "-id", volume, "-cell", cell).splitlines()
86 except shell.CallError:
89 usage = int(result[0].split()[3])
90 limit = int(result[3].split()[1]) # XXX: FRAGILE
92 raise QuotaParseError("vos examine output was:\n\n" + "\n".join(result))
95 # XXX: Possibly in the wrong module
96 def get_disk_usage(dir=None, excluded_dir=".git"):
98 Recursively determines the disk usage of a directory, excluding
99 .git directories. Value is in bytes.
101 if dir is None: dir = os.getcwd()
103 for root, _, files in os.walk(dir):
105 if not os.path.join(root, name).startswith(dir + excluded_dir):
106 sum_sizes += os.path.getsize(os.path.join(root, name))
108 class QuotaParseError(wizard.Error):
109 def __init__(self, msg):
114 ERROR: Could not parse quota. %s