class ConnectionContext(object): def __init__(self): self.conn = None self.bucket = None def __enter__(self): self.conn = s3cp.get_connection() self.bucket = self.conn.get_bucket(bucket_name, False) self.key = Key(self.bucket, key) return self.key def __exit__(self, *vargs): try: self.key.close() except: import logging import traceback logging.warn('some kind of error closing a key:\n%s', traceback.format_exc()) s3cp.return_connection(self.conn) self.conn = None self.bucket = None self.key = None
def main(parser, options, args): for engine in DBSession.query(AmazonS3Storage): bucket = engine.connect_to_bucket() key = Key(bucket) key.key = 'crossdomain.xml' key.set_contents_from_string(CONTENTS, {'Content-Type': 'application/xml'}) key.set_acl('public-read') sys.exit(0) if __name__ == "__main__": main(cmd.parser, cmd.options, cmd.args)
def __enter__(self): self.conn = s3cp.get_connection() self.bucket = self.conn.get_bucket(bucket_name, False) self.key = Key(self.bucket, key) return self.key
def upload_test_file(self): key = Key(name=KEY_NAME, bucket=self.bucket) key.set_contents_from_string( str(datetime.datetime.now()))