1
# Copyright (c) 2006,2007,2008 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
23
from boto.utils import find_class
25
class Manager(object):
27
DefaultDomainName = boto.config.get('Persist', 'default_domain', None)
29
def __init__(self, domain_name=None, aws_access_key_id=None, aws_secret_access_key=None, debug=0):
30
self.domain_name = domain_name
31
self.aws_access_key_id = aws_access_key_id
32
self.aws_secret_access_key = aws_secret_access_key
36
if not self.domain_name:
37
self.domain_name = self.DefaultDomainName
39
boto.log.info('No SimpleDB domain set, using default_domain: %s' % self.domain_name)
41
boto.log.warning('No SimpleDB domain set, persistance is disabled')
43
self.sdb = boto.connect_sdb(aws_access_key_id=self.aws_access_key_id,
44
aws_secret_access_key=self.aws_secret_access_key,
46
self.domain = self.sdb.lookup(self.domain_name)
48
self.domain = self.sdb.create_domain(self.domain_name)
50
def get_s3_connection(self):
52
self.s3 = boto.connect_s3(self.aws_access_key_id, self.aws_secret_access_key)
55
def get_manager(domain_name=None, aws_access_key_id=None, aws_secret_access_key=None, debug=0):
56
return Manager(domain_name, aws_access_key_id, aws_secret_access_key, debug=debug)
58
def set_domain(domain_name):
59
Manager.DefaultDomainName = domain_name
62
return Manager.DefaultDomainName
64
def revive_object_from_id(id, manager):
65
if not manager.domain:
67
attrs = manager.domain.get_attributes(id, ['__module__', '__type__', '__lineage__'])
69
cls = find_class(attrs['__module__'], attrs['__type__'])
70
return cls(id, manager=manager)
74
def object_lister(cls, query_lister, manager):
75
for item in query_lister:
79
o = revive_object_from_id(item.name, manager)