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())
interrupt_id = None if inv.getRequest().getMethod() == "POST": if inv.hasParameter("interrupt"): interrupt_id = inv.getLong("thread-id") Monad.getUtils()["imprt"]( globals(), { "db": ["HhDatum", "Site", "Supply", "set_read_write", "session"], "utils": ["UserException", "HH", "form_date"], "templater": ["render", "on_start_report", "get_report"], }, ) elif inv.hasParameter("run_shutdown"): shutdown_contract = Contract.getNonCoreContract("shutdown") shutdown_contract.callFunction("on_shut_down", [Monad.getContext()]) source.appendChild(MonadMessage("Shut down successfully.").toXml(doc)) elif inv.hasParameter("run_startup"): startup_contract = Contract.getNonCoreContract("startup") startup_contract.callFunction("on_start_up", [Monad.getContext()]) elif inv.hasParameter("cancel_backend"): backend_pid = inv.getLong("backend_pid") con = Hiber.session().connection() stmt = con.createStatement() stmt.execute("select pg_terminate_backend(" + str(backend_pid) + ")") stmt.close() Hiber.commit() source.appendChild(MonadMessage("Cancelled backend.").toXml(doc))
def jython_start(ctx): from net.sf.chellow.billing import Contract from net.sf.chellow.monad import Hiber from org.python.util import PythonInterpreter from java.io import LineNumberReader, File, FileReader from org.python.core import PyString interp = PythonInterpreter() sys_state = interp.getSystemState() lib_path = ctx.getRealPath("/WEB-INF/lib-python") if lib_path is not None: lib_dir = File(lib_path) if lib_dir.exists(): sys_state.path.append(PyString(lib_path)) # Now check for .pth files in lib-python and process each one for lib_content in lib_dir.list(): if lib_content.endswith(".pth"): line_reader = None try: line_reader = LineNumberReader( FileReader(File(lib_path, lib_content))) line = line_reader.readLine() while line is not None: line = line.strip() if len(line) == 0: continue if line.startswith("#"): continue if line.startswith("import"): efunc = getattr(interp, 'exec') efunc(line) continue archive_file = File(lib_path, line) archive_real_path = archive_file.getAbsolutePath() sys_state.path.append(PyString(archive_real_path)) line = line_reader.readLine() finally: line_reader.close() for contract_name in LIBS: contract = Contract.getNonCoreContract(contract_name) nspace = LibDict() nspace['db_id'] = contract.id exec(contract.getChargeScript(), nspace) for k, v in nspace.iteritems(): if not hasattr(nspace, k): setattr(nspace, k, v) ctx.setAttribute("net.sf.chellow." + contract_name, nspace) Hiber.close()