def get_infobase(): """Creates infobase object.""" from infogami.infobase import infobase, dbstore, cache web.config.db_printing = True web.load() # hack to make cache work for local infobase connections cache.loadhook() web.ctx.ip = '127.0.0.1' store = dbstore.DBStore(schema.get_schema()) ib = infobase.Infobase(store, infobase.config.secret_key) if config.writelog: ib.add_event_listener(Logger(config.writelog)) ol = ib.get('openlibrary.org') if ol and config.booklog: global booklogger booklogger = Logger(config.booklog) ol.add_trigger('/type/edition', write_booklog) ol.add_trigger('/type/author', write_booklog2) if ol and config.http_listeners: ol.add_event_listener(None, http_notify) return ib
def bootstrap(site, admin_password): """Creates system types and objects for a newly created site. """ from infogami.infobase import cache cache.loadhook() import web web.ctx.infobase_bootstrap = True query = make_query() site.save_many(query) from infogami.infobase import config import random import string def random_password(length=20): chars = string.letters + string.digits return "".join(random.choice(chars) for i in range(length)) # Account Bot is not created till now. Set account_bot to None in config until he is created. account_bot = config.get("account_bot") config.account_bot = None a = site.get_account_manager() a.register(username="******", email="*****@*****.**", password=admin_password, data=dict(displayname="Administrator"), _activate=True) a.update_user_details("admin", verified=True) if account_bot: username = account_bot.split("/")[-1] a.register(username=username, email="*****@*****.**", password=random_password(), data=dict(displayname=username), _activate=True) a.update_user_details(username, verified=True) # add admin user to admin usergroup from infogami.infobase import account q = [ usergroup('/usergroup/admin', 'Group of admin users.', [{ "key": account.get_user_root() + "admin" }]) ] site.save_many(q) config.account_bot = account_bot web.ctx.infobase_bootstrap = False
def get_site(staging=False): if 'site' in web.ctx: return web.ctx.site rc = read_rc() param = dict((k, rc['staging_' + k if staging else k]) for k in ('db', 'user', 'pw', 'host')) print(param) param['dbn'] = 'postgres' infogami.config.db_parameters = param infogami.config.db_printing = False ib = get_infobase(rc) web.ctx.site = ib.get('openlibrary.org') cache.loadhook() return web.ctx.site
def request(path, method, data): """Fakes the web request. Useful when infobase is not run as a separate process. """ web.ctx.infobase_localmode = True web.ctx.infobase_input = data or {} web.ctx.infobase_method = method def get_class(classname): if '.' in classname: modname, classname = classname.rsplit('.', 1) mod = __import__(modname, None, None, ['x']) fvars = mod.__dict__ else: fvars = globals() return fvars[classname] try: # hack to make cache work for local infobase connections cache.loadhook() mapping = app.mapping # Before web.py<0.36, the mapping is a list and need to be grouped. # From web.py 0.36 onwards, the mapping is already grouped. # Checking the type to see if we need to group them here. if mapping and not isinstance(mapping[0], (list, tuple)): mapping = web.group(mapping, 2) for pattern, classname in mapping: m = web.re_compile('^' + pattern + '$').match(path) if m: args = m.groups() cls = get_class(classname) tocall = getattr(cls(), method) return tocall(*args) raise web.notfound() finally: # hack to make cache work for local infobase connections cache.unloadhook()
def bootstrap(self, admin_password='******'): web.ctx.ip = '127.0.0.1' cache.loadhook() bootstrap.bootstrap(self, admin_password)