def __init__(self, **kwargs): if options.baseurl is None: raise ValueError('Base URL must be configured') router = SockJSRouter(SearchConnection, '/search', self.sockjs_settings) # Allow connections to find the application router.application = self handlers = list(self.handlers) router.apply_routes(handlers) settings = dict(self.app_settings) settings.update(kwargs) tornado.web.Application.__init__(self, handlers, **settings) if not os.path.isdir(options.blob_cache_dir): os.makedirs(options.blob_cache_dir, 0700) self.blob_cache = BlobCache(options.blob_cache_dir) self.search_cache = SearchCache(options.search_cache_dir) self._pruner = threading.Thread(target=self._prune_cache_thread, name='prune-cache') self._pruner.daemon = True self._pruner.start()
def main(host_config_filename, targets_config_filename): config = application_config.load_config(host_config_filename, targets_config_filename) application_logger.initialize_logger(config['logging']) host = config['host'] port = int(config['port']) upload_folder = config['upload_folder'] file_stash_folder = config['file_stash_folder'] queue_folder = config['queue_folder'] num_distribution_processes = int(config['num_distribution_processes']) max_file_age_days = int(config['max_file_age_days']) max_file_age_check_interval_seconds = int(config['max_file_age_check_interval_seconds']) max_task_execution_time_seconds = int(config['max_task_execution_time_seconds']) max_task_finalization_time_seconds = int(config['max_task_finalization_time_seconds']) task_cleanup_interval_seconds = int(config['task_cleanup_interval_seconds']) max_task_wait_seconds = int(config['max_task_wait_seconds']) max_task_exist_days = int(config['max_task_exist_days']) root = Flask(__name__) root.config['host_description'] = config['host_description'] root.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1 sendor_queue = SendorQueue(num_distribution_processes, queue_folder, max_task_execution_time_seconds, max_task_finalization_time_seconds, task_cleanup_interval_seconds, max_task_wait_seconds, max_task_exist_days) file_stash = FileStash(file_stash_folder, max_file_age_days, max_file_age_check_interval_seconds) targets = Targets(config['targets']) ui_app = ui.create_ui(file_stash, upload_folder) root.register_blueprint(url_prefix = '/ui', blueprint = ui_app) rest_api_app = FileDistribution.rest_api.create_rest_api(sendor_queue, targets, file_stash) root.register_blueprint(url_prefix = '/api', blueprint = rest_api_app) FileDistribution.backsync_api.create_backsync_api(sendor_queue, targets, file_stash) @root.route('/') @root.route('/index.html') def index(): return redirect('ui') logger.info("Starting wsgi server") wsgi_root = tornado.wsgi.WSGIContainer(root) backsyncRouter = SockJSRouter(BacksyncModelRouter, '/backsync') handlers = [] backsyncRouter.apply_routes(handlers) handlers.extend([(r".*", tornado.web.FallbackHandler, dict(fallback=wsgi_root))]) application = tornado.web.Application(handlers) application.listen(port) tornado.ioloop.IOLoop.instance().start()
def main(): import core # turn on heavy debug logging #setup_logging() try: SockRouter = SockJSRouter(Status) application = Application( SockRouter.apply_routes([(r"/", IndexHandler), (r"/record", RecordHandler), (r"/resetPeaks", ResetPeaksHandler), (r"/resetBTimer", ResetBTimerHandler), ( r"/flac/(.*)", tornado.web.StaticFileHandler, { "path": "." }, )]), static_path=os.path.join(os.path.dirname(__file__), "static"), debug=sys.DEV_MODE) if not sys.DEV_MODE: port = 80 else: port = 8080 application.listen(port) ioloop.IOLoop.instance().start() finally: core.port.stop() core.port.waitTillFinished()
def main(): import core # turn on heavy debug logging #setup_logging() try: SockRouter = SockJSRouter(Status) application = Application(SockRouter.apply_routes([(r"/", IndexHandler), (r"/record", RecordHandler), (r"/resetPeaks", ResetPeaksHandler), (r"/resetBTimer", ResetBTimerHandler), (r"/flac/(.*)",tornado.web.StaticFileHandler, {"path": "."},)]), static_path = os.path.join(os.path.dirname(__file__), "static"), debug = sys.DEV_MODE ) if not sys.DEV_MODE: port = 80 else: port = 8080 application.listen(port) ioloop.IOLoop.instance().start() finally: core.port.stop() core.port.waitTillFinished()
def start_warrior_server(warrior, bind_address="localhost", port_number=8001, http_username=None, http_password=None): '''Starts the warrior web interface.''' SeesawConnection.warrior = warrior warrior.on_projects_loaded += SeesawConnection.handle_projects_loaded warrior.on_project_refresh += SeesawConnection.handle_project_refresh warrior.on_project_installing += SeesawConnection.handle_project_installing warrior.on_project_installed += SeesawConnection.handle_project_installed warrior.on_project_installation_failed += \ SeesawConnection.handle_project_installation_failed warrior.on_project_selected += SeesawConnection.handle_project_selected warrior.on_broadcast_message_received += SeesawConnection.handle_broadcast_message warrior.on_status += SeesawConnection.handle_warrior_status warrior.runner.on_pipeline_start_item += SeesawConnection.handle_start_item warrior.runner.on_pipeline_finish_item += \ SeesawConnection.handle_finish_item warrior.runner.on_status += SeesawConnection.handle_runner_status if not http_username: http_username = warrior.http_username if not http_password: http_password = warrior.http_password ioloop.PeriodicCallback(SeesawConnection.broadcast_bandwidth, 1000).start() ioloop.PeriodicCallback(SeesawConnection.broadcast_timestamp, 1000).start() router = SockJSRouter(SeesawConnection) application = web.Application( router.apply_routes([(r"/(.*\.(html|css|js|swf|png|ico))$", web.StaticFileHandler, { "path": PUBLIC_PATH }), ("/", IndexHandler), ("/api/(.+)$", ApiHandler, { "warrior": warrior })]), # flash_policy_port = 843, # flash_policy_file = os.path.join(PUBLIC_PATH, "flashpolicy.xml"), socket_io_address=bind_address, socket_io_port=port_number, # settings for AuthenticatedApplication auth_enabled=lambda: (realize(http_password) or "").strip() != "", check_auth=lambda r, username, password: (password == realize(http_password) and (realize(http_username) or "").strip() in ["", username]), auth_realm="ArchiveTeam Warrior", skip_auth=[]) application.listen(port_number, bind_address)
def start_warrior_server(warrior, bind_address="localhost", port_number=8001, http_username=None, http_password=None): '''Starts the warrior web interface.''' SeesawConnection.warrior = warrior warrior.on_projects_loaded += SeesawConnection.handle_projects_loaded warrior.on_project_refresh += SeesawConnection.handle_project_refresh warrior.on_project_installing += SeesawConnection.handle_project_installing warrior.on_project_installed += SeesawConnection.handle_project_installed warrior.on_project_installation_failed += \ SeesawConnection.handle_project_installation_failed warrior.on_project_selected += SeesawConnection.handle_project_selected warrior.on_broadcast_message_received += SeesawConnection.handle_broadcast_message warrior.on_status += SeesawConnection.handle_warrior_status warrior.runner.on_pipeline_start_item += SeesawConnection.handle_start_item warrior.runner.on_pipeline_finish_item += \ SeesawConnection.handle_finish_item warrior.runner.on_status += SeesawConnection.handle_runner_status if not http_username: http_username = warrior.http_username if not http_password: http_password = warrior.http_password ioloop.PeriodicCallback(SeesawConnection.broadcast_bandwidth, 1000).start() ioloop.PeriodicCallback(SeesawConnection.broadcast_timestamp, 1000).start() router = SockJSRouter(SeesawConnection) application = web.Application( router.apply_routes([ (r"/(.*\.(html|css|js|swf|png|ico))$", web.StaticFileHandler, {"path": PUBLIC_PATH}), ("/", IndexHandler), ("/api/(.+)$", ApiHandler, {"warrior": warrior})]), # flash_policy_port = 843, # flash_policy_file = os.path.join(PUBLIC_PATH, "flashpolicy.xml"), socket_io_address=bind_address, socket_io_port=port_number, # settings for AuthenticatedApplication auth_enabled=lambda: (realize(http_password) or "").strip() != "", check_auth=lambda r, username, password: ( password == realize(http_password) and (realize(http_username) or "").strip() in ["", username] ), auth_realm="ArchiveTeam Warrior", skip_auth=[] ) application.listen(port_number, bind_address)
def start_runner_server(project, runner, bind_address="localhost", port_number=8001, http_username=None, http_password=None): '''Starts a web interface for a manually run pipeline. Unlike :func:`start_warrior_server`, this UI does not contain an configuration or project management panel. ''' # if bind_address == "0.0.0.0": # bind_address = "" SeesawConnection.project = project SeesawConnection.runner = runner runner.on_pipeline_start_item += SeesawConnection.handle_start_item runner.on_pipeline_finish_item += SeesawConnection.handle_finish_item runner.on_status += SeesawConnection.handle_runner_status ioloop.PeriodicCallback(SeesawConnection.broadcast_timestamp, 1000).start() router = SockJSRouter(SeesawConnection) application = web.Application( router.apply_routes([(r"/(.*\.(html|css|js|swf|png|ico))$", web.StaticFileHandler, { "path": PUBLIC_PATH }), ("/", IndexHandler), ("/api/(.+)$", ApiHandler, { "runner": runner })]), # flash_policy_port = 843, # flash_policy_file=os.path.join(PUBLIC_PATH, "flashpolicy.xml"), socket_io_address=bind_address, socket_io_port=port_number, # settings for AuthenticatedApplication auth_enabled=(http_password or "").strip() != "", check_auth=lambda r, username, password: (password == http_password and (http_username or "").strip() in ["", username]), auth_realm="ArchiveTeam Warrior", skip_auth=[]) application.listen(port_number, bind_address)
def start_runner_server(project, runner, bind_address="localhost", port_number=8001, http_username=None, http_password=None): '''Starts a web interface for a manually run pipeline. Unlike :func:`start_warrior_server`, this UI does not contain an configuration or project management panel. ''' # if bind_address == "0.0.0.0": # bind_address = "" SeesawConnection.project = project SeesawConnection.runner = runner runner.on_pipeline_start_item += SeesawConnection.handle_start_item runner.on_pipeline_finish_item += SeesawConnection.handle_finish_item runner.on_status += SeesawConnection.handle_runner_status ioloop.PeriodicCallback(SeesawConnection.broadcast_timestamp, 1000).start() router = SockJSRouter(SeesawConnection) application = web.Application( router.apply_routes([ (r"/(.*\.(html|css|js|swf|png|ico))$", web.StaticFileHandler, {"path": PUBLIC_PATH}), ("/", IndexHandler), ("/api/(.+)$", ApiHandler, {"runner": runner})]), # flash_policy_port = 843, # flash_policy_file=os.path.join(PUBLIC_PATH, "flashpolicy.xml"), socket_io_address=bind_address, socket_io_port=port_number, # settings for AuthenticatedApplication auth_enabled=(http_password or "").strip() != "", check_auth=lambda r, username, password: ( password == http_password and (http_username or "").strip() in ["", username] ), auth_realm="ArchiveTeam Warrior", skip_auth=[] ) application.listen(port_number, bind_address)