1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from caldavclientlibrary.browser.command import Command
18 from caldavclientlibrary.browser.command import WrongOptions
19 from caldavclientlibrary.protocol.url import URL
20 import getopt
21 import os
22 import shlex
23 from caldavclientlibrary.protocol.webdav.definitions import davxml
24
26
30
32
33 opts, args = getopt.getopt(shlex.split(options), '')
34
35 for name, _ignore_value in opts:
36
37 print "Unknown option: %s" % (name,)
38 print self.usage(name)
39 raise WrongOptions
40
41 if len(args) > 1:
42 print "Wrong number of arguments: %d" % (len(args),)
43 print self.usage(name)
44 raise WrongOptions
45
46 path = args[0] if len(args) else self.shell.wd
47 if not path.startswith("/"):
48 path = os.path.join(self.shell.wd, path)
49 if not path.endswith("/"):
50 path += "/"
51
52 resource = URL(url=path)
53 results, bad = self.shell.account.session.getProperties(resource, (davxml.quota_available_bytes, davxml.quota_used_bytes))
54 if davxml.quota_available_bytes in bad:
55 print "Could not retrieve DAV:quota-available-bytes property, status=%d" % (bad[davxml.quota_available_bytes],)
56 elif davxml.quota_used_bytes in bad:
57 print "Could not retrieve DAV:quota-used-bytes property, status=%d" % (bad[davxml.quota_used_bytes],)
58 else:
59 quota_available = int(results[davxml.quota_available_bytes])
60 quota_used = int(results[davxml.quota_used_bytes])
61
62 def _printSmartSize(size):
63
64 if size < 1024:
65 return "%d bytes" % (size,)
66 elif size < 1024 * 1024:
67 return "%.1f KB" % (size / 1024.0,)
68 elif size < 1024 * 1024 * 1024:
69 return "%.1f MB" % (size / (1024.0 * 1024.0),)
70 else:
71 return "%.1f GB" % (size / (1024.0 * 1024.0 * 1024.0),)
72
73 print "Used %s of %s (free: %s)" % (
74 _printSmartSize(quota_used),
75 _printSmartSize(quota_used + quota_available),
76 _printSmartSize(quota_available),
77 )
78
79 return True
80
83
85 return """Usage: %s [PATH]
86 PATH is a relative or absolute path.
87
88 """ % (name,)
89
91 return "Checks quota on the specified PATH."
92