def create_app(): """Create and instance of the the pyDEX app from config""" # create an instance of the app app = Flask(__name__) # configure the app from the config #app.config.from_object(config) # override the logger to write to command line and file app.logger = setup_logger("archonwe_app", "archonweb_app.log") # configure the database with the app #db.init_app(app) """ # The following is a hack to make sure the DB is created on init with app.app_context(): db.create_all() """ # import all blueprints and register them with the app #from pydex_app.sra_routes import sra app.register_blueprint(archonweb) return app
#!/usr/bin/env python2 import os import sys import time import signal import json # from tornado.options import options, parse_command_line, define from tornado.ioloop import IOLoop from server import Server from logutils import setup_logger import config logger = setup_logger("boilerplate.main") def handle_signal(sig, frame): logger.warning('Caught signal: %s', sig) IOLoop.instance().add_callback(shutdown) def shutdown(delay=2): """First stop server and add callback to stop i/o loop""" logger.info("Shutdown initiated...") io_loop = IOLoop.instance() io_loop.stop() logger.info("bye")
import os import time import signal import subprocess from threading import Thread, Event from tornado.tcpserver import TCPServer import config from logutils import setup_logger logger = setup_logger("boilerplate.server") class Connection(object): """Client connection handler (one per TCP client)""" address = None def __init__(self, stream, address, server): """Initialize base params and call stream reader for next line""" logger.info("connection - address: %s", address) self.stream = stream self.address = address self.server = server self.stream.set_close_callback(self._on_disconnect) self.wait() def _on_read(self, line): """Called when new line received from connection""" # Some game logic (or magic) line = line.strip()
#!/usr/bin/env python2 import os import sys import time import signal import json # from tornado.options import options, parse_command_line, define from tornado.ioloop import IOLoop from server import Server from logutils import setup_logger import config logger = setup_logger() def handle_signal(sig, frame): logger.warning('Caught signal: %s', sig) IOLoop.instance().add_callback(shutdown) def shutdown(delay=2): """First stop server and add callback to stop i/o loop""" logger.info("Shutdown initiated...") io_loop = IOLoop.instance() io_loop.stop() logger.info("bye")
Copyright (c) 2015, YOUR_NAME License: YOUR_LICENSE """ __title__ = 'Boilerplate' __version__ = '1.0.0' __author__ = 'Chris Hager' __license__ = 'Apache 2.0' __copyright__ = 'Copyright 2015 Chris Hager' import os import sys import argparse from logutils import setup_logger logger = setup_logger() def main(args): #if os.getuid() != 0: # logger.error("Needs to be run as root on a Raspberry") # exit(1) logger.info(args) if __name__ == "__main__": """ This is executed when run from the command line """ parser = argparse.ArgumentParser( description='Command description to show on -v',