def cpython_start(): from chellow import app from chellow.models import Contract libs = {} app.config['libs'] = libs for contract_name in LIBS: try: contract = Contract.get_non_core_by_name(contract_name) nspace = LibDict() nspace['db_id'] = contract.id exec(contract.charge_script, nspace) for k, v in nspace.iteritems(): if not hasattr(nspace, k): setattr(nspace, k, v) libs[contract_name] = nspace except Exception: raise Exception( "While importing " + contract_name + " " + traceback.format_exc())
"from pg_class t, pg_class i, pg_index ix, pg_attribute a, " "pg_namespace where t.oid = ix.indrelid " "and i.oid = ix.indexrelid and a.attrelid = t.oid " "and a.attnum = ANY(ix.indkey) and t.relkind = 'r' " "and t.relnamespace = pg_namespace.oid " "and pg_namespace.nspname = 'public' " "group by t.relname, i.relname, pg_namespace.nspname " "order by t.relname, i.relname" ) return vals sess = None try: sess = db.session() caches = {} if inv.getRequest().getMethod() == "POST": if inv.hasParameter("run_shutdown"): shutdown_contract = Contract.get_non_core_by_name(sess, "shutdown") computer.contract_func(caches, shutdown_contract, "on_shut_down", None)(None) render(inv, template, make_vals(sess, "Shut down successfully.")) elif inv.hasParameter("run_startup"): shutdown_contract = Contract.get_non_core_by_name(sess, "startup") computer.contract_func(caches, shutdown_contract, "on_start_up", None)(None) render(inv, template, make_vals(sess, "Started up successfully.")) else: render(inv, template, make_vals(sess)) finally: if sess is not None: sess.close()