Removed /usr/local from CDPATH
[clearscm.git] / aws / awss3.py
1 #!/usr/bin/python
2
3 import boto3, sys
4 from botocore.exceptions import ClientError
5
6 from display import *
7 import cmd
8
9 # Create an S3 client
10 s3 = boto3.client('s3')
11
12 def AWSError(msg, exception, errno = 0):
13   error(msg + "\n" + str(exception.response['Error']['Message']), errno)
14
15 def listBuckets():
16   # Call S3 to list current buckets
17   response = s3.list_buckets()
18
19   # Get a list of all bucket names from the response
20   buckets = [bucket['Name'] for bucket in response['Buckets']]
21
22   # Print out the bucket list
23   display ('Bucket List: {0}'.format(buckets))
24
25 def createBucket(name):
26   try:
27     s3.create_bucket(Bucket=name, CreateBucketConfiguration={
28       'LocationConstraint': 'us-west-1'})
29   except ClientError as e:
30     AWSError('Unable to create bucket {0}'.format(name), e, 1)
31
32 def cli():
33   #display (__name__ + ':', nolinefeed=True)
34
35   while True:
36     cmd = input('awss3:')
37     print 'Command entered' + cmd
38
39     display ('Command entered ' + cmd)
40
41     if cmd == 'quit' or cmd == 'exit':
42       sys.exit()
43
44 cli()
45
46 listBuckets()
47 createBucket('defaria-aws.com2')
48 listBuckets()