示例#1
0
文件: app.py 项目: dmdm/PySite
    def init_app(self, args):
        """
        Initialises Pyramid application.

        Loads config settings. Initialises SQLAlchemy.
        """
        self._args = args
        setup_logging(self._args.config)
        settings = get_appsettings(self._args.config)

        if 'environment' not in settings:
            raise KeyError('Missing key "environment" in config. Specify '
                'environment in paster INI file.')
        rc = Rc(environment=settings['environment'],
            root_dir=os.path.abspath(
                os.path.join(os.path.dirname(__file__), '..')
            )
        )
        rc.load()
        settings.update(rc.data)
        settings['rc'] = rc

        pysite.models.init(settings, 'db.pysite.sa.')

        self._rc = rc
        self._settings = settings

        pysite._init_vmail(rc)
示例#2
0
文件: __init__.py 项目: dmdm/PySite
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    # Init Rc
    # Get Rc instance like this, then use its methods e.g. g() or s():
    #     request.registry.settings['rc']
    # Rc data is merged directly into settings, so you can retrieve it like
    # this:
    #     request.registry.settings['project']
    # Set Rc's root_dir, which by default is the project dir (not the package
    # dir)
    #     ProjectDir
    #     +-- pym
    #     |   `-- rc.py
    #     `-- PackageDir
    if 'environment' not in settings:
        raise KeyError('Missing key "environment" in config. Specify '
            'environment in paster INI file.')
    rc = Rc(environment=settings['environment'],
        root_dir=os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..')
        )
    )
    rc.load()
    settings.update(rc.data)
    # Put rc into config settings
    settings['rc'] = rc

    # Create config
    config = Configurator(
        settings=settings
    )
    config.include(includeme)

    return config.make_wsgi_app()
示例#3
0
文件: env.py 项目: dmdm/PySite
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = pysite.models.DbBase.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.

PYM_ENV = config.get_main_option("environment")
if not PYM_ENV:
    raise KeyError('Missing key "environment" in config.')
# The directory of the config file is our root_dir
rc = Rc(environment=PYM_ENV,
    root_dir=os.path.normpath(
        os.path.join(os.path.dirname(__file__), '..')
    )
)
rc.load()


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.