Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: third_party/gsutil/20110627/boto/bin/lss3

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 import boto
3
4 def sizeof_fmt(num):
5 for x in ['b ','KB','MB','GB','TB', 'XB']:
6 if num < 1024.0:
7 return "%3.1f %s" % (num, x)
8 num /= 1024.0
9 return "%3.1f %s" % (num, x)
10
11 def list_bucket(b, prefix=None):
12 """List everything in a bucket"""
13 from boto.s3.prefix import Prefix
14 total = 0
15 query = b
16 if prefix:
17 if not prefix.endswith("/"):
18 prefix = prefix + "/"
19 query = b.list(prefix=prefix, delimiter="/")
20 print "%s" % prefix
21 num = 0
22 for k in query:
23 num += 1
24 mode = "-rwx---"
25 if isinstance(k, Prefix):
26 mode = "drwxr--"
27 size = 0
28 else:
29 size = k.size
30 for g in k.get_acl().acl.grants:
31 if g.id == None:
32 if g.permission == "READ":
33 mode = "-rwxr--"
34 elif g.permission == "FULL_CONTROL":
35 mode = "-rwxrwx"
36 print "%s\t%010s\t%s" % (mode, sizeof_fmt(size), k.name)
37 total += size
38 print "="*60
39 print "TOTAL: \t%010s \t%i Files" % (sizeof_fmt(total), num)
40
41 def list_buckets(s3):
42 """List all the buckets"""
43 for b in s3.get_all_buckets():
44 print b.name
45
46 if __name__ == "__main__":
47 import sys
48 s3 = boto.connect_s3()
49 if len(sys.argv) < 2:
50 list_buckets(s3)
51 else:
52 for name in sys.argv[1:]:
53 prefix = None
54 if "/" in name:
55 (name, prefix) = name.split("/",1)
56 list_bucket(s3.get_bucket(name), prefix)
OLDNEW
« no previous file with comments | « third_party/gsutil/20110627/boto/bin/list_instances ('k') | third_party/gsutil/20110627/boto/bin/pyami_sendmail » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698