def handle(self, template='default', *args, **config): if(template in builtin_templates): bootstrap_path = pkg.resource_filename('antioch.core.bootstrap', '%s.py' % template) else: bootstrap_path = template pool = dbapi.connect(settings.DB_URL) bootstrap.load_python(pool, bootstrap_path) bootstrap.initialize_plugins(pool)
def init_database(dbid, dataset='minimal', autocommit=False): global pool if(dbid not in pool and len(pool) == 1): key, p = pool.items()[0] p.close() del pool[key] elif(dbid in pool): return pool[dbid] db_url = settings.DB_URL_TEST bootstrap.initialize_database(psql_path, db_url) schema_path = pkg.resource_filename('antioch.core.bootstrap', 'schema.sql') bootstrap.load_schema(psql_path, db_url, schema_path) pool[dbid] = dbapi.connect(db_url, **dict( autocommit = autocommit, )) bootstrap_path = pkg.resource_filename('antioch.core.bootstrap', '%s.py' % dataset) bootstrap.load_python(pool[dbid], bootstrap_path) return pool[dbid]
from __future__ import absolute_import import logging from celery import shared_task from django.conf import settings from antioch.core import dbapi, code, exchange, errors, parser from antioch.util import sql, json log = logging.getLogger(__name__) log.debug("%s started" % __name__) pool = dbapi.connect(settings.DB_URL_DEFAULT, **dict( autocommit = False )) def get_exchange(ctx=None): """ Get an ObjectExchange instance for the provided context. """ if(ctx): return exchange.ObjectExchange(pool, queue=True, ctx=ctx) else: return exchange.ObjectExchange(pool) @shared_task def authenticate(username, password, ip_address): """ Return the user id for the username/password combo, if valid.
except usage.UsageError, e: print config.getSynopsis() print config.getUsage() print e.args[0] sys.exit(1) if(config['schema-file']): schema_path = config['schema-file'] else: schema_path = pkg.resource_filename('antioch.core.bootstrap', default_schema_path) schema_path = os.path.abspath(schema_path) if(config['bootstrap-file']): bootstrap_path = config['bootstrap-file'] else: bootstrap_path = pkg.resource_filename('antioch.core.bootstrap', default_bootstrap_path % config['dataset-name']) bootstrap_path = os.path.abspath(bootstrap_path) if not(config['no-init']): bootstrap.initialize_database(config['with-psql'], config['db-url'], config['psql-args'], quiet=False) from django.core.management import call_command call_command('syncdb', interactive=False) call_command('migrate', interactive=False) pool = dbapi.connect(config['db-url']) bootstrap.load_python(pool, bootstrap_path) bootstrap.initialize_plugins(pool) if(__name__ == '__main__'): main()