The following script will cause the file to work exactly like the
model.py in your project but only if you have it in the same directory
as your devcfg.py/prodcfg.py.


from turbogears.database import PackageHub
from MYCLASS.model import *

def set_dburi(hub):
    import os
    if os.path.exists("setup.py"):
        if os.path.exists("devcfg.py"):
            config = "devcfg.py"
        else:
            config = "dev.cfg"
    else:
        if os.path.exists("prodcfg.py"):
            config = "prodcfg.py"
        else:
            config = "prod.cfg"
    if os.path.exists(config):
        import cherrypy
        cherrypy.config.update(file=config)
        hub.dburi = cherrypy.config.get("sqlobject.dburi")
    else:
        hub.dburi = None

hub = PackageHub("MYCLASS")
set_dburi(hub)
__connection__ = hub

Reply via email to