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

Side by Side Diff: third_party/gsutil/boto/boto/__init__.py

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/taskadmin ('k') | third_party/gsutil/boto/boto/auth.py » ('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 # Copyright (c) 2006-2012 Mitch Garnaat http://garnaat.org/
2 # Copyright (c) 2010-2011, Eucalyptus Systems, Inc.
3 # Copyright (c) 2011, Nexenta Systems Inc.
4 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates.
5 # Copyright (c) 2010, Google, Inc.
6 # All rights reserved.
7 #
8 # Permission is hereby granted, free of charge, to any person obtaining a
9 # copy of this software and associated documentation files (the
10 # "Software"), to deal in the Software without restriction, including
11 # without limitation the rights to use, copy, modify, merge, publish, dis-
12 # tribute, sublicense, and/or sell copies of the Software, and to permit
13 # persons to whom the Software is furnished to do so, subject to the fol-
14 # lowing conditions:
15 #
16 # The above copyright notice and this permission notice shall be included
17 # in all copies or substantial portions of the Software.
18 #
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
21 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
22 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 # IN THE SOFTWARE.
26 #
27 from boto.pyami.config import Config, BotoConfigLocations
28 from boto.storage_uri import BucketStorageUri, FileStorageUri
29 import boto.plugin
30 import os
31 import platform
32 import re
33 import sys
34 import logging
35 import logging.config
36 import urlparse
37 from boto.exception import InvalidUriError
38
39 __version__ = '2.8.0-dev'
40 Version = __version__ # for backware compatibility
41
42 UserAgent = 'Boto/%s (%s)' % (__version__, sys.platform)
43 config = Config()
44
45 # Regex to disallow buckets violating charset or not [3..255] chars total.
46 BUCKET_NAME_RE = re.compile(r'^[a-z0-9][a-z0-9\._-]{1,253}[a-z0-9]$')
47 # Regex to disallow buckets with individual DNS labels longer than 63.
48 TOO_LONG_DNS_NAME_COMP = re.compile(r'[-_a-z0-9]{64}')
49 GENERATION_RE = re.compile(r'(?P<versionless_uri_str>.+)'
50 r'#(?P<generation>[0-9]+)$')
51 VERSION_RE = re.compile('(?P<versionless_uri_str>.+)#(?P<version_id>.+)$')
52
53
54 def init_logging():
55 for file in BotoConfigLocations:
56 try:
57 logging.config.fileConfig(os.path.expanduser(file))
58 except:
59 pass
60
61
62 class NullHandler(logging.Handler):
63 def emit(self, record):
64 pass
65
66 log = logging.getLogger('boto')
67 perflog = logging.getLogger('boto.perf')
68 log.addHandler(NullHandler())
69 perflog.addHandler(NullHandler())
70 init_logging()
71
72 # convenience function to set logging to a particular file
73
74
75 def set_file_logger(name, filepath, level=logging.INFO, format_string=None):
76 global log
77 if not format_string:
78 format_string = "%(asctime)s %(name)s [%(levelname)s]:%(message)s"
79 logger = logging.getLogger(name)
80 logger.setLevel(level)
81 fh = logging.FileHandler(filepath)
82 fh.setLevel(level)
83 formatter = logging.Formatter(format_string)
84 fh.setFormatter(formatter)
85 logger.addHandler(fh)
86 log = logger
87
88
89 def set_stream_logger(name, level=logging.DEBUG, format_string=None):
90 global log
91 if not format_string:
92 format_string = "%(asctime)s %(name)s [%(levelname)s]:%(message)s"
93 logger = logging.getLogger(name)
94 logger.setLevel(level)
95 fh = logging.StreamHandler()
96 fh.setLevel(level)
97 formatter = logging.Formatter(format_string)
98 fh.setFormatter(formatter)
99 logger.addHandler(fh)
100 log = logger
101
102
103 def connect_sqs(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
104 """
105 :type aws_access_key_id: string
106 :param aws_access_key_id: Your AWS Access Key ID
107
108 :type aws_secret_access_key: string
109 :param aws_secret_access_key: Your AWS Secret Access Key
110
111 :rtype: :class:`boto.sqs.connection.SQSConnection`
112 :return: A connection to Amazon's SQS
113 """
114 from boto.sqs.connection import SQSConnection
115 return SQSConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
116
117
118 def connect_s3(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
119 """
120 :type aws_access_key_id: string
121 :param aws_access_key_id: Your AWS Access Key ID
122
123 :type aws_secret_access_key: string
124 :param aws_secret_access_key: Your AWS Secret Access Key
125
126 :rtype: :class:`boto.s3.connection.S3Connection`
127 :return: A connection to Amazon's S3
128 """
129 from boto.s3.connection import S3Connection
130 return S3Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
131
132
133 def connect_gs(gs_access_key_id=None, gs_secret_access_key=None, **kwargs):
134 """
135 @type gs_access_key_id: string
136 @param gs_access_key_id: Your Google Cloud Storage Access Key ID
137
138 @type gs_secret_access_key: string
139 @param gs_secret_access_key: Your Google Cloud Storage Secret Access Key
140
141 @rtype: L{GSConnection<boto.gs.connection.GSConnection>}
142 @return: A connection to Google's Storage service
143 """
144 from boto.gs.connection import GSConnection
145 return GSConnection(gs_access_key_id, gs_secret_access_key, **kwargs)
146
147
148 def connect_ec2(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
149 """
150 :type aws_access_key_id: string
151 :param aws_access_key_id: Your AWS Access Key ID
152
153 :type aws_secret_access_key: string
154 :param aws_secret_access_key: Your AWS Secret Access Key
155
156 :rtype: :class:`boto.ec2.connection.EC2Connection`
157 :return: A connection to Amazon's EC2
158 """
159 from boto.ec2.connection import EC2Connection
160 return EC2Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
161
162
163 def connect_elb(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
164 """
165 :type aws_access_key_id: string
166 :param aws_access_key_id: Your AWS Access Key ID
167
168 :type aws_secret_access_key: string
169 :param aws_secret_access_key: Your AWS Secret Access Key
170
171 :rtype: :class:`boto.ec2.elb.ELBConnection`
172 :return: A connection to Amazon's Load Balancing Service
173 """
174 from boto.ec2.elb import ELBConnection
175 return ELBConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
176
177
178 def connect_autoscale(aws_access_key_id=None, aws_secret_access_key=None,
179 **kwargs):
180 """
181 :type aws_access_key_id: string
182 :param aws_access_key_id: Your AWS Access Key ID
183
184 :type aws_secret_access_key: string
185 :param aws_secret_access_key: Your AWS Secret Access Key
186
187 :rtype: :class:`boto.ec2.autoscale.AutoScaleConnection`
188 :return: A connection to Amazon's Auto Scaling Service
189 """
190 from boto.ec2.autoscale import AutoScaleConnection
191 return AutoScaleConnection(aws_access_key_id, aws_secret_access_key,
192 **kwargs)
193
194
195 def connect_cloudwatch(aws_access_key_id=None, aws_secret_access_key=None,
196 **kwargs):
197 """
198 :type aws_access_key_id: string
199 :param aws_access_key_id: Your AWS Access Key ID
200
201 :type aws_secret_access_key: string
202 :param aws_secret_access_key: Your AWS Secret Access Key
203
204 :rtype: :class:`boto.ec2.cloudwatch.CloudWatchConnection`
205 :return: A connection to Amazon's EC2 Monitoring service
206 """
207 from boto.ec2.cloudwatch import CloudWatchConnection
208 return CloudWatchConnection(aws_access_key_id, aws_secret_access_key,
209 **kwargs)
210
211
212 def connect_sdb(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
213 """
214 :type aws_access_key_id: string
215 :param aws_access_key_id: Your AWS Access Key ID
216
217 :type aws_secret_access_key: string
218 :param aws_secret_access_key: Your AWS Secret Access Key
219
220 :rtype: :class:`boto.sdb.connection.SDBConnection`
221 :return: A connection to Amazon's SDB
222 """
223 from boto.sdb.connection import SDBConnection
224 return SDBConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
225
226
227 def connect_fps(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
228 """
229 :type aws_access_key_id: string
230 :param aws_access_key_id: Your AWS Access Key ID
231
232 :type aws_secret_access_key: string
233 :param aws_secret_access_key: Your AWS Secret Access Key
234
235 :rtype: :class:`boto.fps.connection.FPSConnection`
236 :return: A connection to FPS
237 """
238 from boto.fps.connection import FPSConnection
239 return FPSConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
240
241
242 def connect_mturk(aws_access_key_id=None, aws_secret_access_key=None,
243 **kwargs):
244 """
245 :type aws_access_key_id: string
246 :param aws_access_key_id: Your AWS Access Key ID
247
248 :type aws_secret_access_key: string
249 :param aws_secret_access_key: Your AWS Secret Access Key
250
251 :rtype: :class:`boto.mturk.connection.MTurkConnection`
252 :return: A connection to MTurk
253 """
254 from boto.mturk.connection import MTurkConnection
255 return MTurkConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
256
257
258 def connect_cloudfront(aws_access_key_id=None, aws_secret_access_key=None,
259 **kwargs):
260 """
261 :type aws_access_key_id: string
262 :param aws_access_key_id: Your AWS Access Key ID
263
264 :type aws_secret_access_key: string
265 :param aws_secret_access_key: Your AWS Secret Access Key
266
267 :rtype: :class:`boto.fps.connection.FPSConnection`
268 :return: A connection to FPS
269 """
270 from boto.cloudfront import CloudFrontConnection
271 return CloudFrontConnection(aws_access_key_id, aws_secret_access_key,
272 **kwargs)
273
274
275 def connect_vpc(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
276 """
277 :type aws_access_key_id: string
278 :param aws_access_key_id: Your AWS Access Key ID
279
280 :type aws_secret_access_key: string
281 :param aws_secret_access_key: Your AWS Secret Access Key
282
283 :rtype: :class:`boto.vpc.VPCConnection`
284 :return: A connection to VPC
285 """
286 from boto.vpc import VPCConnection
287 return VPCConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
288
289
290 def connect_rds(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
291 """
292 :type aws_access_key_id: string
293 :param aws_access_key_id: Your AWS Access Key ID
294
295 :type aws_secret_access_key: string
296 :param aws_secret_access_key: Your AWS Secret Access Key
297
298 :rtype: :class:`boto.rds.RDSConnection`
299 :return: A connection to RDS
300 """
301 from boto.rds import RDSConnection
302 return RDSConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
303
304
305 def connect_emr(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
306 """
307 :type aws_access_key_id: string
308 :param aws_access_key_id: Your AWS Access Key ID
309
310 :type aws_secret_access_key: string
311 :param aws_secret_access_key: Your AWS Secret Access Key
312
313 :rtype: :class:`boto.emr.EmrConnection`
314 :return: A connection to Elastic mapreduce
315 """
316 from boto.emr import EmrConnection
317 return EmrConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
318
319
320 def connect_sns(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
321 """
322 :type aws_access_key_id: string
323 :param aws_access_key_id: Your AWS Access Key ID
324
325 :type aws_secret_access_key: string
326 :param aws_secret_access_key: Your AWS Secret Access Key
327
328 :rtype: :class:`boto.sns.SNSConnection`
329 :return: A connection to Amazon's SNS
330 """
331 from boto.sns import SNSConnection
332 return SNSConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
333
334
335 def connect_iam(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
336 """
337 :type aws_access_key_id: string
338 :param aws_access_key_id: Your AWS Access Key ID
339
340 :type aws_secret_access_key: string
341 :param aws_secret_access_key: Your AWS Secret Access Key
342
343 :rtype: :class:`boto.iam.IAMConnection`
344 :return: A connection to Amazon's IAM
345 """
346 from boto.iam import IAMConnection
347 return IAMConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
348
349
350 def connect_route53(aws_access_key_id=None, aws_secret_access_key=None,
351 **kwargs):
352 """
353 :type aws_access_key_id: string
354 :param aws_access_key_id: Your AWS Access Key ID
355
356 :type aws_secret_access_key: string
357 :param aws_secret_access_key: Your AWS Secret Access Key
358
359 :rtype: :class:`boto.dns.Route53Connection`
360 :return: A connection to Amazon's Route53 DNS Service
361 """
362 from boto.route53 import Route53Connection
363 return Route53Connection(aws_access_key_id, aws_secret_access_key,
364 **kwargs)
365
366
367 def connect_cloudformation(aws_access_key_id=None, aws_secret_access_key=None,
368 **kwargs):
369 """
370 :type aws_access_key_id: string
371 :param aws_access_key_id: Your AWS Access Key ID
372
373 :type aws_secret_access_key: string
374 :param aws_secret_access_key: Your AWS Secret Access Key
375
376 :rtype: :class:`boto.cloudformation.CloudFormationConnection`
377 :return: A connection to Amazon's CloudFormation Service
378 """
379 from boto.cloudformation import CloudFormationConnection
380 return CloudFormationConnection(aws_access_key_id, aws_secret_access_key,
381 **kwargs)
382
383
384 def connect_euca(host=None, aws_access_key_id=None, aws_secret_access_key=None,
385 port=8773, path='/services/Eucalyptus', is_secure=False,
386 **kwargs):
387 """
388 Connect to a Eucalyptus service.
389
390 :type host: string
391 :param host: the host name or ip address of the Eucalyptus server
392
393 :type aws_access_key_id: string
394 :param aws_access_key_id: Your AWS Access Key ID
395
396 :type aws_secret_access_key: string
397 :param aws_secret_access_key: Your AWS Secret Access Key
398
399 :rtype: :class:`boto.ec2.connection.EC2Connection`
400 :return: A connection to Eucalyptus server
401 """
402 from boto.ec2 import EC2Connection
403 from boto.ec2.regioninfo import RegionInfo
404
405 # Check for values in boto config, if not supplied as args
406 if not aws_access_key_id:
407 aws_access_key_id = config.get('Credentials',
408 'euca_access_key_id',
409 None)
410 if not aws_secret_access_key:
411 aws_secret_access_key = config.get('Credentials',
412 'euca_secret_access_key',
413 None)
414 if not host:
415 host = config.get('Boto', 'eucalyptus_host', None)
416
417 reg = RegionInfo(name='eucalyptus', endpoint=host)
418 return EC2Connection(aws_access_key_id, aws_secret_access_key,
419 region=reg, port=port, path=path,
420 is_secure=is_secure, **kwargs)
421
422
423 def connect_glacier(aws_access_key_id=None, aws_secret_access_key=None,
424 **kwargs):
425 """
426 :type aws_access_key_id: string
427 :param aws_access_key_id: Your AWS Access Key ID
428
429 :type aws_secret_access_key: string
430 :param aws_secret_access_key: Your AWS Secret Access Key
431
432 :rtype: :class:`boto.glacier.layer2.Layer2`
433 :return: A connection to Amazon's Glacier Service
434 """
435 from boto.glacier.layer2 import Layer2
436 return Layer2(aws_access_key_id, aws_secret_access_key,
437 **kwargs)
438
439
440 def connect_ec2_endpoint(url, aws_access_key_id=None,
441 aws_secret_access_key=None,
442 **kwargs):
443 """
444 Connect to an EC2 Api endpoint. Additional arguments are passed
445 through to connect_ec2.
446
447 :type url: string
448 :param url: A url for the ec2 api endpoint to connect to
449
450 :type aws_access_key_id: string
451 :param aws_access_key_id: Your AWS Access Key ID
452
453 :type aws_secret_access_key: string
454 :param aws_secret_access_key: Your AWS Secret Access Key
455
456 :rtype: :class:`boto.ec2.connection.EC2Connection`
457 :return: A connection to Eucalyptus server
458 """
459 from boto.ec2.regioninfo import RegionInfo
460
461 purl = urlparse.urlparse(url)
462 kwargs['port'] = purl.port
463 kwargs['host'] = purl.hostname
464 kwargs['path'] = purl.path
465 if not 'is_secure' in kwargs:
466 kwargs['is_secure'] = (purl.scheme == "https")
467
468 kwargs['region'] = RegionInfo(name=purl.hostname,
469 endpoint=purl.hostname)
470 kwargs['aws_access_key_id'] = aws_access_key_id
471 kwargs['aws_secret_access_key'] = aws_secret_access_key
472
473 return(connect_ec2(**kwargs))
474
475
476 def connect_walrus(host=None, aws_access_key_id=None,
477 aws_secret_access_key=None,
478 port=8773, path='/services/Walrus', is_secure=False,
479 **kwargs):
480 """
481 Connect to a Walrus service.
482
483 :type host: string
484 :param host: the host name or ip address of the Walrus server
485
486 :type aws_access_key_id: string
487 :param aws_access_key_id: Your AWS Access Key ID
488
489 :type aws_secret_access_key: string
490 :param aws_secret_access_key: Your AWS Secret Access Key
491
492 :rtype: :class:`boto.s3.connection.S3Connection`
493 :return: A connection to Walrus
494 """
495 from boto.s3.connection import S3Connection
496 from boto.s3.connection import OrdinaryCallingFormat
497
498 # Check for values in boto config, if not supplied as args
499 if not aws_access_key_id:
500 aws_access_key_id = config.get('Credentials',
501 'euca_access_key_id',
502 None)
503 if not aws_secret_access_key:
504 aws_secret_access_key = config.get('Credentials',
505 'euca_secret_access_key',
506 None)
507 if not host:
508 host = config.get('Boto', 'walrus_host', None)
509
510 return S3Connection(aws_access_key_id, aws_secret_access_key,
511 host=host, port=port, path=path,
512 calling_format=OrdinaryCallingFormat(),
513 is_secure=is_secure, **kwargs)
514
515
516 def connect_ses(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
517 """
518 :type aws_access_key_id: string
519 :param aws_access_key_id: Your AWS Access Key ID
520
521 :type aws_secret_access_key: string
522 :param aws_secret_access_key: Your AWS Secret Access Key
523
524 :rtype: :class:`boto.ses.SESConnection`
525 :return: A connection to Amazon's SES
526 """
527 from boto.ses import SESConnection
528 return SESConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
529
530
531 def connect_sts(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
532 """
533 :type aws_access_key_id: string
534 :param aws_access_key_id: Your AWS Access Key ID
535
536 :type aws_secret_access_key: string
537 :param aws_secret_access_key: Your AWS Secret Access Key
538
539 :rtype: :class:`boto.sts.STSConnection`
540 :return: A connection to Amazon's STS
541 """
542 from boto.sts import STSConnection
543 return STSConnection(aws_access_key_id, aws_secret_access_key, **kwargs)
544
545
546 def connect_ia(ia_access_key_id=None, ia_secret_access_key=None,
547 is_secure=False, **kwargs):
548 """
549 Connect to the Internet Archive via their S3-like API.
550
551 :type ia_access_key_id: string
552 :param ia_access_key_id: Your IA Access Key ID. This will also look
553 in your boto config file for an entry in the Credentials
554 section called "ia_access_key_id"
555
556 :type ia_secret_access_key: string
557 :param ia_secret_access_key: Your IA Secret Access Key. This will also
558 look in your boto config file for an entry in the Credentials
559 section called "ia_secret_access_key"
560
561 :rtype: :class:`boto.s3.connection.S3Connection`
562 :return: A connection to the Internet Archive
563 """
564 from boto.s3.connection import S3Connection
565 from boto.s3.connection import OrdinaryCallingFormat
566
567 access_key = config.get('Credentials', 'ia_access_key_id',
568 ia_access_key_id)
569 secret_key = config.get('Credentials', 'ia_secret_access_key',
570 ia_secret_access_key)
571
572 return S3Connection(access_key, secret_key,
573 host='s3.us.archive.org',
574 calling_format=OrdinaryCallingFormat(),
575 is_secure=is_secure, **kwargs)
576
577
578 def connect_dynamodb(aws_access_key_id=None,
579 aws_secret_access_key=None,
580 **kwargs):
581 """
582 :type aws_access_key_id: string
583 :param aws_access_key_id: Your AWS Access Key ID
584
585 :type aws_secret_access_key: string
586 :param aws_secret_access_key: Your AWS Secret Access Key
587
588 :rtype: :class:`boto.dynamodb.layer2.Layer2`
589 :return: A connection to the Layer2 interface for DynamoDB.
590 """
591 from boto.dynamodb.layer2 import Layer2
592 return Layer2(aws_access_key_id, aws_secret_access_key, **kwargs)
593
594
595 def connect_swf(aws_access_key_id=None,
596 aws_secret_access_key=None,
597 **kwargs):
598 """
599 :type aws_access_key_id: string
600 :param aws_access_key_id: Your AWS Access Key ID
601
602 :type aws_secret_access_key: string
603 :param aws_secret_access_key: Your AWS Secret Access Key
604
605 :rtype: :class:`boto.swf.layer1.Layer1`
606 :return: A connection to the Layer1 interface for SWF.
607 """
608 from boto.swf.layer1 import Layer1
609 return Layer1(aws_access_key_id, aws_secret_access_key, **kwargs)
610
611
612 def connect_cloudsearch(aws_access_key_id=None,
613 aws_secret_access_key=None,
614 **kwargs):
615 """
616 :type aws_access_key_id: string
617 :param aws_access_key_id: Your AWS Access Key ID
618
619 :type aws_secret_access_key: string
620 :param aws_secret_access_key: Your AWS Secret Access Key
621
622 :rtype: :class:`boto.ec2.autoscale.CloudSearchConnection`
623 :return: A connection to Amazon's CloudSearch service
624 """
625 from boto.cloudsearch.layer2 import Layer2
626 return Layer2(aws_access_key_id, aws_secret_access_key,
627 **kwargs)
628
629
630 def connect_beanstalk(aws_access_key_id=None,
631 aws_secret_access_key=None,
632 **kwargs):
633 """
634 :type aws_access_key_id: string
635 :param aws_access_key_id: Your AWS Access Key ID
636
637 :type aws_secret_access_key: string
638 :param aws_secret_access_key: Your AWS Secret Access Key
639
640 :rtype: :class:`boto.beanstalk.layer1.Layer1`
641 :return: A connection to Amazon's Elastic Beanstalk service
642 """
643 from boto.beanstalk.layer1 import Layer1
644 return Layer1(aws_access_key_id, aws_secret_access_key, **kwargs)
645
646
647 def connect_elastictranscoder(aws_access_key_id=None,
648 aws_secret_access_key=None,
649 **kwargs):
650 """
651 :type aws_access_key_id: string
652 :param aws_access_key_id: Your AWS Access Key ID
653
654 :type aws_secret_access_key: string
655 :param aws_secret_access_key: Your AWS Secret Access Key
656
657 :rtype: :class:`boto.ets.layer1.ElasticTranscoderConnection`
658 :return: A connection to Amazon's Elastic Transcoder service
659 """
660 from boto.elastictranscoder.layer1 import ElasticTranscoderConnection
661 return ElasticTranscoderConnection(
662 aws_access_key_id=aws_access_key_id,
663 aws_secret_access_key=aws_secret_access_key,
664 **kwargs)
665
666
667 def storage_uri(uri_str, default_scheme='file', debug=0, validate=True,
668 bucket_storage_uri_class=BucketStorageUri,
669 suppress_consec_slashes=True, is_latest=False):
670 """
671 Instantiate a StorageUri from a URI string.
672
673 :type uri_str: string
674 :param uri_str: URI naming bucket + optional object.
675 :type default_scheme: string
676 :param default_scheme: default scheme for scheme-less URIs.
677 :type debug: int
678 :param debug: debug level to pass in to boto connection (range 0..2).
679 :type validate: bool
680 :param validate: whether to check for bucket name validity.
681 :type bucket_storage_uri_class: BucketStorageUri interface.
682 :param bucket_storage_uri_class: Allows mocking for unit tests.
683 :param suppress_consec_slashes: If provided, controls whether
684 consecutive slashes will be suppressed in key paths.
685 :type is_latest: bool
686 :param is_latest: whether this versioned object represents the
687 current version.
688
689 We allow validate to be disabled to allow caller
690 to implement bucket-level wildcarding (outside the boto library;
691 see gsutil).
692
693 :rtype: :class:`boto.StorageUri` subclass
694 :return: StorageUri subclass for given URI.
695
696 ``uri_str`` must be one of the following formats:
697
698 * gs://bucket/name
699 * gs://bucket/name#ver
700 * s3://bucket/name
701 * gs://bucket
702 * s3://bucket
703 * filename (which could be a Unix path like /a/b/c or a Windows path like
704 C:\a\b\c)
705
706 The last example uses the default scheme ('file', unless overridden).
707 """
708 version_id = None
709 generation = None
710
711 # Manually parse URI components instead of using urlparse.urlparse because
712 # what we're calling URIs don't really fit the standard syntax for URIs
713 # (the latter includes an optional host/net location part).
714 end_scheme_idx = uri_str.find('://')
715 if end_scheme_idx == -1:
716 # Check for common error: user specifies gs:bucket instead
717 # of gs://bucket. Some URI parsers allow this, but it can cause
718 # confusion for callers, so we don't.
719 colon_pos = uri_str.find(':')
720 if colon_pos != -1:
721 # Allow Windows path names including drive letter (C: etc.)
722 drive_char = uri_str[0].lower()
723 if not (platform.system().lower().startswith('windows')
724 and colon_pos == 1
725 and drive_char >= 'a' and drive_char <= 'z'):
726 raise InvalidUriError('"%s" contains ":" instead of "://"' %
727 uri_str)
728 scheme = default_scheme.lower()
729 path = uri_str
730 else:
731 scheme = uri_str[0:end_scheme_idx].lower()
732 path = uri_str[end_scheme_idx + 3:]
733
734 if scheme not in ['file', 's3', 'gs']:
735 raise InvalidUriError('Unrecognized scheme "%s"' % scheme)
736 if scheme == 'file':
737 # For file URIs we have no bucket name, and use the complete path
738 # (minus 'file://') as the object name.
739 is_stream = False
740 if path == '-':
741 is_stream = True
742 return FileStorageUri(path, debug, is_stream)
743 else:
744 path_parts = path.split('/', 1)
745 bucket_name = path_parts[0]
746 object_name = ''
747 # If validate enabled, ensure the bucket name is valid, to avoid
748 # possibly confusing other parts of the code. (For example if we didn't
749 # catch bucket names containing ':', when a user tried to connect to
750 # the server with that name they might get a confusing error about
751 # non-integer port numbers.)
752 if (validate and bucket_name and
753 (not BUCKET_NAME_RE.match(bucket_name)
754 or TOO_LONG_DNS_NAME_COMP.search(bucket_name))):
755 raise InvalidUriError('Invalid bucket name in URI "%s"' % uri_str)
756 if scheme == 'gs':
757 match = GENERATION_RE.search(path)
758 if match:
759 md = match.groupdict()
760 versionless_uri_str = md['versionless_uri_str']
761 path_parts = versionless_uri_str.split('/', 1)
762 generation = int(md['generation'])
763 elif scheme == 's3':
764 match = VERSION_RE.search(path)
765 if match:
766 md = match.groupdict()
767 versionless_uri_str = md['versionless_uri_str']
768 path_parts = versionless_uri_str.split('/', 1)
769 version_id = md['version_id']
770 else:
771 raise InvalidUriError('Unrecognized scheme "%s"' % scheme)
772 if len(path_parts) > 1:
773 object_name = path_parts[1]
774 return bucket_storage_uri_class(
775 scheme, bucket_name, object_name, debug,
776 suppress_consec_slashes=suppress_consec_slashes,
777 version_id=version_id, generation=generation, is_latest=is_latest)
778
779
780 def storage_uri_for_key(key):
781 """Returns a StorageUri for the given key.
782
783 :type key: :class:`boto.s3.key.Key` or subclass
784 :param key: URI naming bucket + optional object.
785 """
786 if not isinstance(key, boto.s3.key.Key):
787 raise InvalidUriError('Requested key (%s) is not a subclass of '
788 'boto.s3.key.Key' % str(type(key)))
789 prov_name = key.bucket.connection.provider.get_provider_name()
790 uri_str = '%s://%s/%s' % (prov_name, key.bucket.name, key.name)
791 return storage_uri(uri_str)
792
793 boto.plugin.load_plugins(config)
OLDNEW
« no previous file with comments | « third_party/gsutil/boto/bin/taskadmin ('k') | third_party/gsutil/boto/boto/auth.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698