def teardown_class(cls): if cls.stop_for_interaction: print "Pausing for interaction at 0.0.0.0:8000..." make_app(cls.config()).run(host='0.0.0.0', port=8000) print "Cleaning up indices..." cls._delete_es_indices() rmtree(cls._config_dir_path)
def main(): parser = OptionParser(usage='usage: %prog [options] build-folder', add_help_option=False) parser.add_option('--help', action='help') parser.add_option('-a', '--all', dest='host', action='store_const', const='0.0.0.0', help='Serve on all interfaces. Equivalent to --host 0.0.0.0') parser.add_option('-h', '--host', dest='host', type='string', default='localhost', help='The host address to serve on') parser.add_option('-j', '--jobs', dest='processes', type='int', default=1, help='The number of processes to use') parser.add_option('-p', '--port', dest='port', type='int', default=8000, help='The port to serve on') parser.add_option('-t', '--threaded', dest='threaded', action='store_true', default=False, help='Use a separate thread for each request') options, args = parser.parse_args() if len(args) == 1: app = make_app(abspath(args[0])) app.debug = True app.run(host=options.host, port=options.port, processes=options.processes, threaded=options.threaded) else: parser.print_usage()
def index_chunk(tree, tree_indexers, paths, index, swallow_exc=False, worker_number=None): """Index a pile of files. This is the entrypoint for indexer pool workers. :arg worker_number: A unique number assigned to this worker so it knows what to call its log file """ path = '(no file yet)' try: # So we can use Flask's url_from(): with make_app(tree.config).test_request_context(): es = current_app.es try: # Don't log if single-process: log = (worker_number and open_log( tree.log_folder, 'index-chunk-%s.log' % worker_number)) for path in paths: log and log.write('Starting %s.\n' % path) index_file(tree, tree_indexers, path, es, index) log and log.write('Finished chunk.\n') finally: log and log.close() except Exception as exc: if swallow_exc: type, value, traceback = exc_info() return format_exc(), type, value, path else: raise
def serve(config, host, workers, port, threaded): """Run a toy version of the web app. This is a simply test server for DXR, not suitable for production use. For actual deployments, use a web server with WSGI support. """ app = make_app(config) app.debug = True app.run(host=host, port=port, processes=workers, threaded=threaded)
def main(): parser = OptionParser(usage='usage: %prog [options] build-folder') parser.add_option('-p', '--port', dest='port', type='int', default=8000, help='The port to serve on') options, args = parser.parse_args() if len(args) == 1: app = make_app(abspath(args[0])) app.debug = True # Without binding to a public interface (0.0.0.0), you can't get to the # Vagrant box's test server from the host machine. app.run(host='0.0.0.0', port=options.port) else: parser.print_usage()
def application(environ, start_response): """Pull the instance path out of an env var, and then instantiate the WSGI app as normal. This prefers the Apache SetEnv sort of environment; but if that's missing, try the process-level env var instead since it's easier to set for some users, like those using Stackato. """ try: dxr_folder = environ['DXR_FOLDER'] except KeyError: # Not found in WSGI env. Try process env: # If this still fails, this is a fatal error. dxr_folder = os.environ['DXR_FOLDER'] return make_app(dxr_folder)(environ, start_response)
def deploy_if_appropriate(self): """Deploy a new build if we should.""" with nonblocking_lock('dxr-deploy-%s' % self.kind) as got_lock: if got_lock: with make_app(self.config).app_context(): try: rev = self.rev_to_deploy() new_build_path = self.build(rev) old_build_path = self.install(new_build_path) except ShouldNotDeploy as exc: log(exc) else: # if not self.passes_smoke_test(): # self.rollback() # else: self.delete_old(old_build_path) log('Deployed revision %s.' % (rev,))
def shell(config, plain): """Run a Python interactive interpreter.""" app = make_app(config) app.debug = True with app.app_context(): namespace = {'app': app, 'config': config} if plain: _plain_shell(namespace) else: for shell in _shells: try: shell(namespace) except ImportError: pass else: break
def application(environ, start_response): """Pull the config file path out of an env var, and then instantiate the WSGI app as normal. This prefers the Apache SetEnv sort of environment; but if that's missing, try the process-level env var instead since it's easier to set for some users, like those using Stackato. """ try: config_path = environ['DXR_CONFIG'] except KeyError: # Not found in WSGI env. Try process env: # If this still fails, this is a fatal error. config_path = os.environ['DXR_CONFIG'] return make_app(Config(file_text(config_path), relative_to=dirname(config_path)))(environ, start_response)
def index_chunk(tree, tree_indexers, paths, index, swallow_exc=False, worker_number=None): """Index a pile of files. This is the entrypoint for indexer pool workers. :arg worker_number: A unique number assigned to this worker so it knows what to call its log file """ path = '(no file yet)' try: # So we can use Flask's url_from(): with make_app(tree.config).test_request_context(): es = current_app.es try: # Don't log if single-process: log = (worker_number and open_log(tree.log_folder, 'index-chunk-%s.log' % worker_number)) for path in paths: log and log.write('Starting %s.\n' % path.encode('utf-8')) index_file(tree, tree_indexers, path, es, index) log and log.write('Finished chunk.\n') finally: log and log.close() except Exception as exc: if swallow_exc: type, value, traceback = exc_info() return format_exc(), type, value, path else: raise
def client(self): # TODO: DRY between here and the config file with 'target'. app = make_app(os.path.join(self._config_dir_path, 'target')) app.config['TESTING'] = True # Disable error trapping during requests. return app.test_client()
import ctypes import os import os.path # Fake out the path to libtrilite.so old_CDLL = ctypes.CDLL def replacement_CDLL(name, mode=ctypes.DEFAULT_MODE, handle=None, use_errno=False, use_last_error=False): if name == "libtrilite.so": name = os.path.expanduser("~/dxr/trilite/libtrilite.so") return old_CDLL(name, mode, handle, use_errno, use_last_error) ctypes.CDLL = replacement_CDLL try: from dxr.app import make_app app = make_app(os.path.abspath(os.environ["DXR_FOLDER"])) app.debug = True app.run(host=os.environ["VCAP_APP_HOST"], port=int(os.environ["VCAP_APP_PORT"]), processes=1, threaded=False) except Exception as ex: import logging import sys logging.basicConfig(stream=sys.stdout) logging.root.exception(ex) # Fall back to avoid begin killed by Stackato from flask import Flask app = Flask("DXR-server-fallback", instance_path=os.path.abspath(os.environ["DXR_FOLDER"]))
def app(self): if not hasattr(self, '_app'): self._app = make_app(self.config()) self._app.config['TESTING'] = True # Disable error trapping during requests. return self._app
def client(self): self._app = make_app(self.config()) self._app.config[ 'TESTING'] = True # Disable error trapping during requests. return self._app.test_client()
def app(self): if not hasattr(self, '_app'): self._app = make_app(self.config()) self._app.config[ 'TESTING'] = True # Disable error trapping during requests. return self._app
def teardown_class(cls): if cls.stop_for_interaction: print "Pausing for interaction at 0.0.0.0:8000..." make_app(cls.config()).run(host='0.0.0.0', port=8000) print "Cleaning up indices..." super(GenerativeTestCase, cls).teardown_class()
def client(self): self._app = make_app(self.config()) self._app.config['TESTING'] = True # Disable error trapping during requests. return self._app.test_client()