Example #1
0
def make_application():
    from tg import MinimalApplicationConfigurator

    config = MinimalApplicationConfigurator()
    config.update_blueprint({'root_controller': RootController()})

    return config.make_wsgi_app()
Example #2
0
 def setup_class(cls):
     config = MinimalApplicationConfigurator()
     config.update_blueprint({
         'root_controller': RootController(),
         'csrf.secret': 'MYSECRET',
     })
     config.register(CSRFConfigurationComponent)
     config.register(SessionConfigurationComponent)
     cls.wsgi_app = config.make_wsgi_app()
Example #3
0
from wsgiref.simple_server import make_server
from tg import MinimalApplicationConfigurator
from tg import expose, TGController


# RootController of our web app, in charge of serving content for /
class RootController(TGController):
    @expose(content_type="text/plain")
    def index(self):
        return 'Hello World'


# Configure a new minimal application with our root controller.
config = MinimalApplicationConfigurator()
config.update_blueprint({
    'root_controller': RootController()
})

# Serve the newly configured web application.
print("Serving on port 8080...")
httpd = make_server('', 8080, config.make_wsgi_app())
httpd.serve_forever()
from tg import MinimalApplicationConfigurator

config = MinimalApplicationConfigurator()
config.register(StaticsConfigurationComponent)  # for static files
config.register(SQLAlchemyConfigurationComponent)

config.update_blueprint({
    'model':
    Bunch(DBSession=DBSession, init_model=init_model),
    'root_controller':
    RootController(),
    'renderers': ['kajiki'],
    'helpers':
    webhelpers2,
    'serve_static':
    True,
    'paths': {
        'static_files':
        'public'  # can now access any static files in public directory e.g. http://localhost:8080/styles.css
    },
    'use_sqlalchemy':
    True,
    'sqlalchemy.url':
    'sqlite:///devdata.db'  # equivalent of url in SQLAlchemy tutourial in base.py
})

application = config.make_wsgi_app()

# serve
from wsgiref.simple_server import make_server
Example #5
0
class Log(DeclarativeBase):
    __tablename__ = 'logs'

    uid = Column(Integer, primary_key=True)
    timestamp = Column(DateTime, nullable=False, default=datetime.utcnow)
    person = Column(String(50), nullable=False)


def init_model(engine):
    DBSession.configure(bind=engine)
    DeclarativeBase.metadata.create_all(engine)


config = MinimalApplicationConfigurator()
config.register(SQLAlchemyConfigurationComponent)
config.update_blueprint({
    'use_sqlalchemy': True,
    'sqlalchemy.url': 'postgres://*****:*****@localhost:5432/postgres',
    'root_controller': RootController(),
    'renderers': ['kajiki'],
    'model': Bunch(
        DBSession=DBSession,
        init_model=init_model
    )
})
application = config.make_wsgi_app()
print("Serving on port 8080!")
httpd = make_server('', 8080, application)
httpd.serve_forever()
Example #6
0
                        default=False,
                        help="define Metalibm verbosity level")
    args = parser.parse_args()

    # Serve the newly configured web application.
    PORT = args.port
    LOCALHOST = args.localhost
    VERSION_INFO = args.version_info
    # Configure a new minimal application with our root controller.
    config = MinimalApplicationConfigurator()
    config.register(StaticsConfigurationComponent)
    config.update_blueprint({
        'root_controller':
        RootController(LOCALHOST, VERSION_INFO, disable_log=args.disable_log),
        'renderers': ['kajiki'],
        'templating.kajiki.template_extension':
        '.xhtml',
        'templating.kajiki.force_mode':
        'html5',
    })
    config.update_blueprint({
        "serve_static": True,
        "paths": {
            "static_files": os.path.join(MetalibmWebApp.SCRIPT_DIR, "public")
        }
    })

    print("Serving on port {}...".format(PORT))
    print("LOCALHOST is {}...".format(LOCALHOST))
    print("VERSION_INFO is {}...".format(VERSION_INFO))
    httpd = make_server('', PORT, config.make_wsgi_app())
Example #7
0
    @expose()
    def process_delete(self, uid=None):
        contact = DBSession.query(Contact).get(uid)
        DBSession.delete(contact)
        DBSession.commit()
        redirect('./')

    @expose('aggiungi_contatto.xhtml')
    def aggiungi_contatto(self, person=None):
        DBSession.add(Log(person=person or ''))
        DBSession.commit()
        return dict(person=person)

config = MinimalApplicationConfigurator()
config.update_blueprint({
    'root_controller': RootController(),
    'renderers': ['kajiki']
})

config.update_blueprint({
    'helpers': webhelpers2
})

config.register(StaticsConfigurationComponent)
config.update_blueprint({
    'serve_static': True,
    'paths': {
        'static_files': 'public'
    }
})

config.register(SQLAlchemyConfigurationComponent)

config = MinimalApplicationConfigurator()
config.register(StaticsConfigurationComponent)  # for static files
config.register(SQLAlchemyConfigurationComponent)

# For TurboGears serve our controller we must create the actual application:
config.update_blueprint({
    'model':
    Bunch(DBSession=DBSession, init_model=init_model),
    'root_controller':
    RootController(),
    'renderers': ['kajiki'],
    'helpers':
    webhelpers2,
    'serve_static':
    True,
    'paths': {
        'static_files': 'public'
    },
    'use_sqlalchemy':
    True,
    'sqlalchemy.url':
    'sqlite:///devdata.db'  # equivalent of url in SQLAlchemy tutourial in base.py
})

application = config.make_wsgi_app()

print("Serving on port 8080...")
httpd = make_server('', 8080, application)
httpd.serve_forever()
Example #9
0
                w.set_input(app_cfg['lg']['ps4'])
            elif cmd == "lg_power_on":
                send_magic_packet(app_cfg['lg']['mac'])
            elif cmd == "lg_power_off":
                w.power_off()
            else:
                return '{"response":"invalid_cmd"}'

            return '{"response":"ok"}'

        else:
            return '{"response":"invalid_cmd"}'


config = MinimalApplicationConfigurator()
config.register(StaticsConfigurationComponent)
config.update_blueprint({
    'root_controller': RootController(),
    'serve_static': True,
    'paths': {
        'static_files': 'static'
    }
})
config.register(SessionConfigurationComponent)
config.serve_static = True
#config.paths['static_files'] = 'static'
stream = open('config.yml', 'r')
app_cfg = yaml.load(stream)['c10tv']
print('Serving on port ' + str(app_cfg['port']) + '...')
httpd = make_server('', app_cfg['port'], config.make_wsgi_app())
httpd.serve_forever()