1
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
3
# Permission is hereby granted, free of charge, to any person obtaining a
4
# copy of this software and associated documentation files (the
5
# "Software"), to deal in the Software without restriction, including
6
# without limitation the rights to use, copy, modify, merge, publish, dis-
7
# tribute, sublicense, and/or sell copies of the Software, and to permit
8
# persons to whom the Software is furnished to do so, subject to the fol-
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
from boto.pyami.config import Config
23
from boto.services.message import ServiceMessage
26
class ServiceDef(Config):
28
def __init__(self, config_file, aws_access_key_id=None, aws_secret_access_key=None):
29
Config.__init__(self, config_file)
30
self.aws_access_key_id = aws_access_key_id
31
self.aws_secret_access_key = aws_secret_access_key
32
script = Config.get(self, 'Pyami', 'scripts')
34
self.name = script.split('.')[-1]
39
def get(self, name, default=None):
40
return Config.get(self, self.name, name, default)
42
def has_option(self, option):
43
return Config.has_option(self, self.name, option)
45
def getint(self, option, default=0):
47
val = Config.get(self, self.name, option)
53
def getbool(self, option, default=False):
55
val = Config.get(self, self.name, option)
56
if val.lower() == 'true':
64
def get_obj(self, name):
66
Returns the AWS object associated with a given option.
68
The heuristics used are a bit lame. If the option name contains
69
the word 'bucket' it is assumed to be an S3 bucket, if the name
70
contains the word 'queue' it is assumed to be an SQS queue and
71
if it contains the word 'domain' it is assumed to be a SimpleDB
72
domain. If the option name specified does not exist in the
73
config file or if the AWS object cannot be retrieved this
79
if name.find('queue') >= 0:
80
obj = boto.lookup('sqs', val)
82
obj.set_message_class(ServiceMessage)
83
elif name.find('bucket') >= 0:
84
obj = boto.lookup('s3', val)
85
elif name.find('domain') >= 0:
86
obj = boto.lookup('sdb', val)