def __init__(self, db_path, encode_keys=False): simpledb.SimpleDB.__init__(self, db_path, encode_keys=False) self._row_listeners = {} self._ruledb = simpledb.SimpleDB(db_path, db_name="rules", encode_keys=False) self._rules = {} self._evaluator = RuleEvaluator() self._evaluator.start()
def initialize_backend(self): simpledbconn = simpledb.SimpleDB( # Evidently the connection can't deal with unicode keys str(self.aws_access_key_id), str(self.aws_secret_access_key), ) domain_name = self.domain # Ensure the SimpleDB domain is created if not simpledbconn.has_domain(domain_name): simpledbconn.create_domain(domain_name) # Now we have to do some voodoo lifted from the metaclass #` simpledb.models:ModelMetaclass.__new__` so that all of the ORM magic # works # We have to do all of this nonsense so that we can avoid declaring the # SimpleDB connection object at class definition time and instead # declare it at the instantiation time of its environment manager simpledbconn.encoder = FieldEncoder( InfrastructureNode.fields, ) domain = simpledb.Domain( domain_name, simpledbconn, ) domain.model = InfrastructureNode class SimpleDBMeta: pass SimpleDBMeta.connection = simpledbconn SimpleDBMeta.domain = domain InfrastructureNode.Meta = SimpleDBMeta
def setUp(self): self._db_root = mktmpdir() logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s", filename="/tmp/testlog") self.db = simpledb.SimpleDB(self._db_root) self.db.Open(create_if_necessary=True)
def __init__(self, domain, params): BaseStorage.__init__(self, params) params = dict(params) try: aws_access_key = params['aws_access_key'] aws_secret_access_key = params['aws_secret_access_key'] except KeyError: raise ImproperlyConfigured( "Incomplete configuration of SimpleDB key-value store. Required parameters: 'aws_access_key', and 'aws_secret_access_key'." ) self._db = simpledb.SimpleDB(aws_access_key, aws_secret_access_key) self._domain = self._db[domain]
def handle(self, *args, **options): apps = AppCache() check = [] for module in apps.get_apps(): for d in module.__dict__: ref = getattr(module, d) if isinstance(ref, simpledb.models.ModelMetaclass): domain = ref.Meta.domain.name if domain not in check: check.append(domain) sdb = simpledb.SimpleDB(settings.AWS_KEY, settings.AWS_SECRET) domains = [d.name for d in list(sdb)] for c in check: if c not in domains: sdb.create_domain(c) print "Creating domain %s ..." % c
def getSDBInstance(name): try: if GlobalIns.__sdb.has_key( name) and GlobalIns.__sdb[name]['IsInited']: return GlobalIns.__sdb[name]['obj'] cfg = GlobalIns.getCfgInstance() if None == cfg: printerr("getSDBInstance: getCfgInstance failed") return None if not GlobalIns.__sdb.has_key(name): GlobalIns.__sdb[name] = copy.deepcopy(INSTANCE_TEMP) db_host = cfg.get(name, 'ip') db_port = int(cfg.get(name, 'port')) db_user = cfg.get(name, 'user') db_passwd = cfg.get(name, 'passwd') db_timeout = 5 if cfg.has_option(name, 'timeout'): db_timeout = int(cfg.get(name, 'timeout')) db_dbname = '' if cfg.has_option(name, 'dbname'): db_dbname = cfg.get(name, 'dbname') db_tbname = '' if cfg.has_option(name, 'tablename'): db_tbname = cfg.get(name, 'tablename') sdbconfig = simpledb.SimpleDBConfig(db_host, db_port, db_user, db_passwd, db_timeout, db_dbname, db_tbname) GlobalIns.__sdb[name]['obj'] = simpledb.SimpleDB(sdbconfig) rst = GlobalIns.__sdb[name]['obj'].initDB() if 0 != rst._resultcode: printerr(rst) return None GlobalIns.__sdb[name]['IsInited'] = True return GlobalIns.__sdb[name]['obj'] except Exception, e: printerr(e) return None
def getSDBInstance(name): try: if GlobalIns.__sdb.has_key( name) and GlobalIns.__sdb[name]['IsInited']: return GlobalIns.__sdb[name]['obj'] rst, cfg = GlobalIns.getCfgInstance() if 0 != rst._resultcode or None == cfg: return CBasicResult(-1, "getSDBInstance failed", -1, "getCfgInstance None"), None if not GlobalIns.__sdb.has_key(name): GlobalIns.__sdb[name] = copy.deepcopy(INSTANCE_TEMP) db_host = cfg.get(name, 'ip') db_port = int(cfg.get(name, 'port')) db_user = cfg.get(name, 'user') db_passwd = cfg.get(name, 'passwd') db_timeout = 5 if cfg.has_option(name, 'timeout'): db_timeout = int(cfg.get(name, 'timeout')) db_dbname = '' if cfg.has_option(name, 'dbname'): db_dbname = cfg.get(name, 'dbname') db_tbname = '' if cfg.has_option(name, 'tablename'): db_tbname = cfg.get(name, 'tablename') sdbconfig = simpledb.SimpleDBConfig(db_host, db_port, db_user, db_passwd, db_timeout, db_dbname, db_tbname) GlobalIns.__sdb[name]['obj'] = simpledb.SimpleDB(sdbconfig) rst = GlobalIns.__sdb[name]['obj'].initDB() if 0 != rst._resultcode: return CBasicResult(-1, "getSDBInstance failed", -1, rst), None GlobalIns.__sdb[name]['IsInited'] = True return CBasicResult(), GlobalIns.__sdb[name]['obj'] except ConfigParser.Error, e: return CBasicResult(-1, "getSDBInstance failed", -1, e), None
from __future__ import unicode_literals from __future__ import absolute_import __author__ = '*****@*****.**' import os.path import ConfigParser import simpledb import time if __name__ == "__main__": my_credentials = ConfigParser.SafeConfigParser() with open(os.path.expanduser("~/.aws_creds")) as fp: my_credentials.readfp(fp) sdb = simpledb.SimpleDB(my_credentials.get('aws', 'access key id'), my_credentials.get('aws', 'Secret Access Key')) frotz_domain = sdb['frotz'] frotz_domain['test'] = dict( action="a value with spaces", snorgulous=u'an ellipsis:\u2026', frotz=u'a nasty Unicode character:\ufffd', ) time.sleep(2) # git clone http://github.com/sixapart/python-simpledb.git # cd python-simpledb # python setup.py build # Local Variables:
domain = sdb.create_domain(domain) else: domain = sdb[domain] # Load the items. for name, value in items.iteritems(): domain[name] = value if __name__ == '__main__': import os import sys sys.path.insert(1, os.path.normpath(os.path.join(sys.path[0], '..'))) import simpledb import settings if len(sys.argv) != 3: print 'Usage: python sdbimport.py <domain> <json_file>' sys.exit(1) print "Loading..." items = simplejson.load(open(sys.argv[2])) print "Importing..." sdb = simpledb.SimpleDB(settings.AWS_KEY, settings.AWS_SECRET) sdbimport(sdb, sys.argv[1], items) print "All done."
def __init__(self, db=db, messenger=messaging): self.db = db.SimpleDB() self.db.get_or_create_domain() self.messenger = messenger.TwilioClient()
def start_transaction(self): # Transactions need their own non-transaction SimpleDB connections. sdb = simpledb.SimpleDB(self.aws_key, self.aws_secret) self.transaction_stack.append(SimpleDBTransaction(sdb, self.data))