Exemplo n.º 1
0
def make_application():
    from tg import MinimalApplicationConfigurator

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

    return config.make_wsgi_app()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 4
0
    @expose('hello.xhtml')
    def hello(self, person=None):
        DBSession.add(Log(person=person or ''))
        DBSession.commit()
        return dict(person=person)


# Passing parameters to your controllers is as simple as adding
# them to the url with the same name of the parameters in your method,
# TurboGears will automatically map them to function arguments when calling an exposed method.
# e.g. http://localhost:8080/hello?person=MyName

# configurator
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':
Exemplo n.º 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()
Exemplo n.º 6
0
                        default=False,
                        help="disable logging of information in gcloud")
    parser.add_argument("--ml-verbose",
                        dest="verbose_enable",
                        action=VerboseAction,
                        const=True,
                        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")
        }
Exemplo n.º 7
0
    @validate({'uid': NotEmpty})
    @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'
    }
Exemplo n.º 8
0
            elif cmd == "lg_input_ps4":
                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())
Exemplo n.º 9
0
                consumer_key=rar_config['consumer_key'],
                redirect_uri=rar_config['redirect_uri'])
        except Exception as e:
            return '<h1 style="color: red">' + str(e)
        session['request_token'] = request_token
        session.save()
        try:
            auth_url = Pocket.get_auth_url(
                code=request_token, redirect_uri=rar_config['redirect_uri'])
        except Exception as e:
            return '<h1 style="color: red">' + str(e)

        print("REQUEST_TOKEN= %s" % (request_token))

        return writeJSRedir(auth_url)

    @expose(content_type='text/html')
    def logout(self):
        session.delete()
        return writeJSRedir('/index')


config = MinimalApplicationConfigurator()
config.update_blueprint({'root_controller': RootController()})
config.register(SessionConfigurationComponent)
stream = open('config.yml', 'r')
rar_config = yaml.load(stream, Loader=yaml.SafeLoader)['rar_config']
print(('Serving on port ' + str(rar_config['port']) + '...'))
httpd = make_server('', rar_config['port'], config.make_wsgi_app())
httpd.serve_forever()