AWS user Kantale

From PyPedia
Jump to: navigation, search

Contents

[edit] Documentation

This is a helper class that uses boto library to handle various Amazon Web Services.

[edit] Parameters

<inputs>
</inputs>

[edit] Return

[edit] See also

[edit] Code

import os

from boto.s3.connection import S3Connection
from boto.s3.connection import Location
from boto.s3.key import Key

class AWS_user_Kantale():

	def __init__(self, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY):
		self.conn = None
		self.AWS_ACCESS_KEY_ID = AWS_ACCESS_KEY_ID
		self.AWS_SECRET_ACCESS_KEY = AWS_SECRET_ACCESS_KEY
		self.connect()

	def connect(self):
		self.conn = S3Connection(self.AWS_ACCESS_KEY_ID, self.AWS_SECRET_ACCESS_KEY)

	def create_bucket(self, name, location=Location.EU):
		bucket = self.conn.create_bucket(name, location=location)
		return bucket

	def get_bucket(self, name):
		rs = self.conn.get_all_buckets()
		for b in rs:
			if b.name == name:
				return b

		raise Exception('Could not find bucket named: ' + str(name))

	def put_file(self, bucket, local_path, bucket_path, verbose = False):
		k = Key(bucket)
		k.key = bucket_path
		if verbose:
			print "Bucket: ", bucket.name, ". Sending local file:", local_path, ' to remote path: ', bucket_path
		k.set_contents_from_filename(local_path)

	def put_directory(self, bucket, local_path, bucket_dir, verbose = False):
		contents = os.listdir(local_path)
		for content in contents:
			local_file_path = os.path.join(local_path, content)
			remote_file_path = os.path.join(bucket_dir, content)
			if os.path.isdir(local_file_path):
				put_directory(bucket, local_file_path, remote_file_path)
			else:
				put_file(bucket, local_file_path, remote_file_path, verbose)

[edit] Unit Tests

def uni1():
	return True

[edit] Development Code

def AWS_user_Kantale():
	pass

[edit] Permissions

[edit] Documentation Permissions

Kantale

[edit] Code Permissions

Kantale

[edit] Unit Tests Permissions

Kantale

[edit] Permissions Permissions

Kantale

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox