Example #1
0
File: wsgi.py Project: joyxu/beaker
def init():
    # Make TG's run_with_transaction a no-op, we manage the transaction here
    # through Flask instead.
    import turbogears.database

    def run_with_transaction_noop(func, *args, **kwargs):
        return func(*args, **kwargs)

    turbogears.database.run_with_transaction = run_with_transaction_noop

    class EndTransactionsFilterNoop(BaseFilter):
        pass

    turbogears.database.EndTransactionsFilter = EndTransactionsFilterNoop
    turbogears.startup.EndTransactionsFilter = EndTransactionsFilterNoop

    # Make TG's restart_transaction not call session.close(). We are
    # responsible for calling session.close() here at the very end of the
    # Flask request, and if TG does it during its validation error handling, it
    # will break identity.
    def restart_transaction_patched(args):
        session.rollback()
        session.begin()

    turbogears.database.restart_transaction = restart_transaction_patched

    # Set up old CherryPy stuff.
    import bkr.server.controllers
    cherrypy.root = bkr.server.controllers.Root()
    cherrypy.server.start(init_only=True, server_class=None)

    # If rlimit_as is defined in the config file then set the limit here.
    if config.get('rlimit_as'):
        import resource
        resource.setrlimit(resource.RLIMIT_AS,
                           (config.get('rlimit_as'), config.get('rlimit_as')))

    # Build assets. If assets.auto_build is True in the config, this will also
    # happen on page request. Otherwise, it only happens once at startup here.
    assets.build_assets()

    # workaround for TGMochiKit initialisation
    # https://sourceforge.net/p/turbogears1/tickets/34/
    import tgmochikit
    from turbogears.widgets.base import register_static_directory
    tgmochikit.init(register_static_directory, config)

    # Global device class list... a terrible hack, desperately needs deleting
    from bkr.server import model
    with session.begin():
        model.device_classes = [
            c.device_class for c in model.DeviceClass.query
        ]

    log.debug('Application initialised')
Example #2
0
def init():
    # Make TG's run_with_transaction a no-op, we manage the transaction here 
    # through Flask instead.
    import turbogears.database
    def run_with_transaction_noop(func, *args, **kwargs):
        return func(*args, **kwargs)
    turbogears.database.run_with_transaction = run_with_transaction_noop
    class EndTransactionsFilterNoop(BaseFilter): pass
    turbogears.database.EndTransactionsFilter = EndTransactionsFilterNoop
    turbogears.startup.EndTransactionsFilter = EndTransactionsFilterNoop

    # Make TG's restart_transaction not call session.close(). We are 
    # responsible for calling session.close() here at the very end of the 
    # Flask request, and if TG does it during its validation error handling, it 
    # will break identity.
    def restart_transaction_patched(args):
        session.rollback()
        session.begin()
    turbogears.database.restart_transaction = restart_transaction_patched

    # Set up old CherryPy stuff.
    import bkr.server.controllers
    cherrypy.root = bkr.server.controllers.Root()
    cherrypy.server.start(init_only=True, server_class=None)

    # If rlimit_as is defined in the config file then set the limit here.
    if config.get('rlimit_as'):
        import resource
        resource.setrlimit(resource.RLIMIT_AS, (config.get('rlimit_as'),
                                                config.get('rlimit_as')))

    # Build assets. If assets.auto_build is True in the config, this will also
    # happen on page request. Otherwise, it only happens once at startup here.
    assets.build_assets()

    # workaround for TGMochiKit initialisation
    # https://sourceforge.net/p/turbogears1/tickets/34/
    import tgmochikit
    from turbogears.widgets.base import register_static_directory
    tgmochikit.init(register_static_directory, config)

    # Global device class list... a terrible hack, desperately needs deleting
    from bkr.server import model
    with session.begin():
        model.device_classes = [c.device_class for c in model.DeviceClass.query]

    log.debug('Application initialised')
Example #3
0
 def run(self):
     self.copy_tree(self.source_dir, self.build_dir)
     log.info('building assets in %s', self.build_dir)
     build_assets(self.build_dir)