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

Side by Side Diff: bin/s3put

Issue 8386013: Merging in latest boto. (Closed) Base URL: svn://svn.chromium.org/boto
Patch Set: Redoing vendor drop by deleting and then merging. Created 9 years, 1 month 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
« no previous file with comments | « bin/s3multiput ('k') | boto/__init__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2006,2007,2008 Mitch Garnaat http://garnaat.org/ 2 # Copyright (c) 2006,2007,2008 Mitch Garnaat http://garnaat.org/
3 # 3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a 4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the 5 # copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including 6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish, dis- 7 # without limitation the rights to use, copy, modify, merge, publish, dis-
8 # tribute, sublicense, and/or sell copies of the Software, and to permit 8 # tribute, sublicense, and/or sell copies of the Software, and to permit
9 # persons to whom the Software is furnished to do so, subject to the fol- 9 # persons to whom the Software is furnished to do so, subject to the fol-
10 # lowing conditions: 10 # lowing conditions:
(...skipping 12 matching lines...) Expand all
23 import getopt, sys, os 23 import getopt, sys, os
24 import boto 24 import boto
25 from boto.exception import S3ResponseError 25 from boto.exception import S3ResponseError
26 26
27 usage_string = """ 27 usage_string = """
28 SYNOPSIS 28 SYNOPSIS
29 s3put [-a/--access_key <access_key>] [-s/--secret_key <secret_key>] 29 s3put [-a/--access_key <access_key>] [-s/--secret_key <secret_key>]
30 -b/--bucket <bucket_name> [-c/--callback <num_cb>] 30 -b/--bucket <bucket_name> [-c/--callback <num_cb>]
31 [-d/--debug <debug_level>] [-i/--ignore <ignore_dirs>] 31 [-d/--debug <debug_level>] [-i/--ignore <ignore_dirs>]
32 [-n/--no_op] [-p/--prefix <prefix>] [-q/--quiet] 32 [-n/--no_op] [-p/--prefix <prefix>] [-q/--quiet]
33 [-g/--grant grant] [-w/--no_overwrite] path 33 [-g/--grant grant] [-w/--no_overwrite] [-r/--reduced] path
34 34
35 Where 35 Where
36 access_key - Your AWS Access Key ID. If not supplied, boto will 36 access_key - Your AWS Access Key ID. If not supplied, boto will
37 use the value of the environment variable 37 use the value of the environment variable
38 AWS_ACCESS_KEY_ID 38 AWS_ACCESS_KEY_ID
39 secret_key - Your AWS Secret Access Key. If not supplied, boto 39 secret_key - Your AWS Secret Access Key. If not supplied, boto
40 will use the value of the environment variable 40 will use the value of the environment variable
41 AWS_SECRET_ACCESS_KEY 41 AWS_SECRET_ACCESS_KEY
42 bucket_name - The name of the S3 bucket the file(s) should be 42 bucket_name - The name of the S3 bucket the file(s) should be
43 copied to. 43 copied to.
(...skipping 23 matching lines...) Expand all
67 grant - A canned ACL policy that will be granted on each file 67 grant - A canned ACL policy that will be granted on each file
68 transferred to S3. The value of provided must be one 68 transferred to S3. The value of provided must be one
69 of the "canned" ACL policies supported by S3: 69 of the "canned" ACL policies supported by S3:
70 private|public-read|public-read-write|authenticated-read 70 private|public-read|public-read-write|authenticated-read
71 no_overwrite - No files will be overwritten on S3, if the file/key 71 no_overwrite - No files will be overwritten on S3, if the file/key
72 exists on s3 it will be kept. This is useful for 72 exists on s3 it will be kept. This is useful for
73 resuming interrupted transfers. Note this is not a 73 resuming interrupted transfers. Note this is not a
74 sync, even if the file has been updated locally if 74 sync, even if the file has been updated locally if
75 the key exists on s3 the file on s3 will not be 75 the key exists on s3 the file on s3 will not be
76 updated. 76 updated.
77 reduced - Use Reduced Redundancy storage
78
77 79
78 If the -n option is provided, no files will be transferred to S3 but 80 If the -n option is provided, no files will be transferred to S3 but
79 informational messages will be printed about what would happen. 81 informational messages will be printed about what would happen.
80 """ 82 """
81 def usage(): 83 def usage():
82 print usage_string 84 print usage_string
83 sys.exit() 85 sys.exit()
84 86
85 def submit_cb(bytes_so_far, total_bytes): 87 def submit_cb(bytes_so_far, total_bytes):
86 print '%d bytes transferred / %d bytes total' % (bytes_so_far, total_bytes) 88 print '%d bytes transferred / %d bytes total' % (bytes_so_far, total_bytes)
87 89
88 def get_key_name(fullpath, prefix): 90 def get_key_name(fullpath, prefix):
89 key_name = fullpath[len(prefix):] 91 key_name = fullpath[len(prefix):]
90 l = key_name.split(os.sep) 92 l = key_name.split(os.sep)
91 return '/'.join(l) 93 return '/'.join(l)
92 94
93 def main(): 95 def main():
94 try: 96 try:
95 opts, args = getopt.getopt(sys.argv[1:], 'a:b:c::d:g:hi:np:qs:vw', 97 opts, args = getopt.getopt(
96 ['access_key', 'bucket', 'callback', 'debug', 'help', 'grant', 98 sys.argv[1:], 'a:b:c::d:g:hi:np:qs:vwr',
97 'ignore', 'no_op', 'prefix', 'quiet', 'secre t_key', 'no_overwrite']) 99 ['access_key', 'bucket', 'callback', 'debug', 'help', 'grant',
100 'ignore', 'no_op', 'prefix', 'quiet', 'secret_key',
101 'no_overwrite', 'reduced']
102 )
98 except: 103 except:
99 usage() 104 usage()
100 ignore_dirs = [] 105 ignore_dirs = []
101 aws_access_key_id = None 106 aws_access_key_id = None
102 aws_secret_access_key = None 107 aws_secret_access_key = None
103 bucket_name = '' 108 bucket_name = ''
104 total = 0 109 total = 0
105 debug = 0 110 debug = 0
106 cb = None 111 cb = None
107 num_cb = 0 112 num_cb = 0
108 quiet = False 113 quiet = False
109 no_op = False 114 no_op = False
110 prefix = '/' 115 prefix = '/'
111 grant = None 116 grant = None
112 no_overwrite = False 117 no_overwrite = False
118 reduced = False
113 for o, a in opts: 119 for o, a in opts:
114 if o in ('-h', '--help'): 120 if o in ('-h', '--help'):
115 usage() 121 usage()
116 sys.exit() 122 sys.exit()
117 if o in ('-a', '--access_key'): 123 if o in ('-a', '--access_key'):
118 aws_access_key_id = a 124 aws_access_key_id = a
119 if o in ('-b', '--bucket'): 125 if o in ('-b', '--bucket'):
120 bucket_name = a 126 bucket_name = a
121 if o in ('-c', '--callback'): 127 if o in ('-c', '--callback'):
122 num_cb = int(a) 128 num_cb = int(a)
123 cb = submit_cb 129 cb = submit_cb
124 if o in ('-d', '--debug'): 130 if o in ('-d', '--debug'):
125 debug = int(a) 131 debug = int(a)
126 if o in ('-g', '--grant'): 132 if o in ('-g', '--grant'):
127 grant = a 133 grant = a
128 if o in ('-i', '--ignore'): 134 if o in ('-i', '--ignore'):
129 ignore_dirs = a.split(',') 135 ignore_dirs = a.split(',')
130 if o in ('-n', '--no_op'): 136 if o in ('-n', '--no_op'):
131 no_op = True 137 no_op = True
132 if o in ('w', '--no_overwrite'): 138 if o in ('-w', '--no_overwrite'):
133 no_overwrite = True 139 no_overwrite = True
140 if o in ('-r', '--reduced'):
141 reduced = True
134 if o in ('-p', '--prefix'): 142 if o in ('-p', '--prefix'):
135 prefix = a 143 prefix = a
136 if prefix[-1] != os.sep: 144 if prefix[-1] != os.sep:
137 prefix = prefix + os.sep 145 prefix = prefix + os.sep
138 if o in ('-q', '--quiet'): 146 if o in ('-q', '--quiet'):
139 quiet = True 147 quiet = True
140 if o in ('-s', '--secret_key'): 148 if o in ('-s', '--secret_key'):
141 aws_secret_access_key = a 149 aws_secret_access_key = a
142 if len(args) != 1: 150 if len(args) != 1:
143 print usage() 151 print usage()
(...skipping 23 matching lines...) Expand all
167 if no_overwrite: 175 if no_overwrite:
168 if key_name in keys: 176 if key_name in keys:
169 copy_file = False 177 copy_file = False
170 if not quiet: 178 if not quiet:
171 print 'Skipping %s as it exists in s3' % file 179 print 'Skipping %s as it exists in s3' % file
172 if copy_file: 180 if copy_file:
173 if not quiet: 181 if not quiet:
174 print 'Copying %s to %s/%s' % (file, bucket_name, ke y_name) 182 print 'Copying %s to %s/%s' % (file, bucket_name, ke y_name)
175 if not no_op: 183 if not no_op:
176 k = b.new_key(key_name) 184 k = b.new_key(key_name)
177 k.set_contents_from_filename(fullpath, cb=cb, 185 k.set_contents_from_filename(
178 num_cb=num_cb, polic y=grant) 186 fullpath, cb=cb, num_cb=num_cb,
187 policy=grant, reduced_redundancy=reduced,
188 )
179 total += 1 189 total += 1
180 elif os.path.isfile(path): 190 elif os.path.isfile(path):
181 key_name = os.path.split(path)[1] 191 key_name = os.path.split(path)[1]
182 copy_file = True 192 copy_file = True
183 if no_overwrite: 193 if no_overwrite:
184 if b.get_key(key_name): 194 if b.get_key(key_name):
185 copy_file = False 195 copy_file = False
186 if not quiet: 196 if not quiet:
187 print 'Skipping %s as it exists in s3' % path 197 print 'Skipping %s as it exists in s3' % path
188 if copy_file: 198 if copy_file:
189 k = b.new_key(key_name) 199 k = b.new_key(key_name)
190 k.set_contents_from_filename(path, cb=cb, num_cb=num_cb, policy= grant) 200 k.set_contents_from_filename(path, cb=cb, num_cb=num_cb,
201 policy=grant,
202 reduced_redundancy=reduced)
191 else: 203 else:
192 print usage() 204 print usage()
193 205
194 if __name__ == "__main__": 206 if __name__ == "__main__":
195 main() 207 main()
196 208
OLDNEW
« no previous file with comments | « bin/s3multiput ('k') | boto/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698