universalsoftware/uchat
2
1 2import os3import sys4import atexit5import time6 7import mod_wsgi.server8 9working_directory = r'/Users/zoranpopovic/uchat/uchat'10 11entry_point = r'/Users/zoranpopovic/uchat/uchat/wsgi.py'12application_type = 'script'13callable_object = 'application'14mount_point = '/'15with_newrelic_agent = False16newrelic_config_file = ''17newrelic_environment = ''18disable_reloading = False19reload_on_changes = False20debug_mode = False21enable_debugger = False22debugger_startup = False23enable_coverage = False24coverage_directory = ''25enable_profiler = False26profiler_directory = ''27enable_recorder = False28recorder_directory = ''29enable_gdb = False30 31os.environ['MOD_WSGI_EXPRESS'] = 'true'32os.environ['MOD_WSGI_SERVER_NAME'] = 'localhost'33os.environ['MOD_WSGI_SERVER_ALIASES'] = None or ''34 35if reload_on_changes:36 os.environ['MOD_WSGI_RELOADER_ENABLED'] = 'true'37 38if debug_mode:39 os.environ['MOD_WSGI_DEBUG_MODE'] = 'true'40 41 # We need to fiddle sys.path as we are not using daemon mode and so42 # the working directory will not be added to sys.path by virtue of43 # 'home' option to WSGIDaemonProcess directive. We could use the44 # WSGIPythonPath directive, but that will cause .pth files to also45 # be evaluated.46 47 sys.path.insert(0, working_directory)48 49if enable_debugger:50 os.environ['MOD_WSGI_DEBUGGER_ENABLED'] = 'true'51 52def output_coverage_report():53 coverage_info.stop()54 coverage_info.html_report(directory=coverage_directory)55 56if enable_coverage:57 os.environ['MOD_WSGI_COVERAGE_ENABLED'] = 'true'58 59 from coverage import coverage60 coverage_info = coverage()61 coverage_info.start()62 atexit.register(output_coverage_report)63 64def output_profiler_data():65 profiler_info.disable()66 output_file = '%s-%d.pstats' % (int(time.time()*1000000), os.getpid())67 output_file = os.path.join(profiler_directory, output_file)68 profiler_info.dump_stats(output_file)69 70if enable_profiler:71 os.environ['MOD_WSGI_PROFILER_ENABLED'] = 'true'72 73 from cProfile import Profile74 profiler_info = Profile()75 profiler_info.enable()76 atexit.register(output_profiler_data)77 78if enable_recorder:79 os.environ['MOD_WSGI_RECORDER_ENABLED'] = 'true'80 81if enable_gdb:82 os.environ['MOD_WSGI_GDB_ENABLED'] = 'true'83 84if with_newrelic_agent:85 if newrelic_config_file:86 os.environ['NEW_RELIC_CONFIG_FILE'] = newrelic_config_file87 if newrelic_environment:88 os.environ['NEW_RELIC_ENVIRONMENT'] = newrelic_environment89 90handler = mod_wsgi.server.ApplicationHandler(entry_point,91 application_type=application_type, callable_object=callable_object,92 mount_point=mount_point, with_newrelic_agent=with_newrelic_agent,93 debug_mode=debug_mode, enable_debugger=enable_debugger,94 debugger_startup=debugger_startup, enable_recorder=enable_recorder,95 recorder_directory=recorder_directory)96 97if not disable_reloading:98 reload_required = handler.reload_required99 100handle_request = handler.handle_request101 102if not disable_reloading and reload_on_changes and not debug_mode:103 mod_wsgi.server.start_reloader()104 105 