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

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

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 7 years, 9 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
« no previous file with comments | « third_party/gsutil/boto/bin/list_instances ('k') | third_party/gsutil/boto/bin/mturk » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 import boto
3 from boto.s3.connection import OrdinaryCallingFormat
4
5 def sizeof_fmt(num):
6 for x in ['b ','KB','MB','GB','TB', 'XB']:
7 if num < 1024.0:
8 return "%3.1f %s" % (num, x)
9 num /= 1024.0
10 return "%3.1f %s" % (num, x)
11
12 def list_bucket(b, prefix=None):
13 """List everything in a bucket"""
14 from boto.s3.prefix import Prefix
15 from boto.s3.key import Key
16 total = 0
17 query = b
18 if prefix:
19 if not prefix.endswith("/"):
20 prefix = prefix + "/"
21 query = b.list(prefix=prefix, delimiter="/")
22 print "%s" % prefix
23 num = 0
24 for k in query:
25 num += 1
26 mode = "-rwx---"
27 if isinstance(k, Prefix):
28 mode = "drwxr--"
29 size = 0
30 else:
31 size = k.size
32 for g in k.get_acl().acl.grants:
33 if g.id == None:
34 if g.permission == "READ":
35 mode = "-rwxr--"
36 elif g.permission == "FULL_CONTROL":
37 mode = "-rwxrwx"
38 if isinstance(k, Key):
39 print "%s\t%s\t%010s\t%s" % (mode, k.last_modified,
40 sizeof_fmt(size), k.name)
41 else:
42 #If it's not a Key object, it doesn't have a last_modified time, so
43 #print nothing instead
44 print "%s\t%s\t%010s\t%s" % (mode, ' '*24,
45 sizeof_fmt(size), k.name)
46 total += size
47 print "="*80
48 print "\t\tTOTAL: \t%010s \t%i Files" % (sizeof_fmt(total), num)
49
50 def list_buckets(s3):
51 """List all the buckets"""
52 for b in s3.get_all_buckets():
53 print b.name
54
55 if __name__ == "__main__":
56 import sys
57
58 pairs = []
59 mixedCase = False
60 for name in sys.argv[1:]:
61 if "/" in name:
62 pairs.append(name.split("/",1))
63 else:
64 pairs.append([name, None])
65 if pairs[-1][0].lower() != pairs[-1][0]:
66 mixedCase = True
67
68 if mixedCase:
69 s3 = boto.connect_s3(calling_format=OrdinaryCallingFormat())
70 else:
71 s3 = boto.connect_s3()
72
73 if len(sys.argv) < 2:
74 list_buckets(s3)
75 else:
76 for name, prefix in pairs:
77 list_bucket(s3.get_bucket(name), prefix)
OLDNEW
« no previous file with comments | « third_party/gsutil/boto/bin/list_instances ('k') | third_party/gsutil/boto/bin/mturk » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698