def main(): # Set null device file path to stdout, stdin, stderr if they are None for _name in ('stdin', 'stdout', 'stderr'): if getattr(sys, _name) is None: setattr(sys, _name, open(os.devnull, 'r' if _name == 'stdin' else 'w')) # Build Javascript files when DEBUG if config.DEBUG: from pgadmin.utils.javascript.javascript_bundler import \ JavascriptBundler, JsState app.debug = True javascriptBundler = JavascriptBundler() javascriptBundler.bundle() if javascriptBundler.report() == JsState.NONE: app.logger.error( "Unable to generate javascript.\n" "To run the app ensure that yarn install command runs " "successfully") raise Exception("No generated javascript, aborting") # Output a startup message if we're not under the runtime and startup. # If we're under WSGI, we don't need to worry about this if not app.PGADMIN_RUNTIME: print("Starting %s. Please navigate to http://%s:%d in your browser." % (config.APP_NAME, config.DEFAULT_SERVER, config.EFFECTIVE_SERVER_PORT)) sys.stdout.flush() else: # For unknown reason the Qt runtime does not pass the environment # variables (i.e. PYTHONHOME, and PYTHONPATH), to the Python # sub-processes, leading to failures executing background processes. # # This has been observed only on windows. On *nix systems, it is likely # picking the system python environment, which is good enough to run # the process-executor. # # Setting PYTHONHOME launch them properly. from pgadmin.utils import IS_WIN if IS_WIN: os.environ['PYTHONHOME'] = sys.prefix # Initialize Flask service only once # If `WERKZEUG_RUN_MAIN` is None, i.e: app is initializing for first time # so set `use_reloader` = False, thus reload won't call. # Reference: # https://github.com/pallets/werkzeug/issues/220#issuecomment-11176538 try: app.run( host=config.DEFAULT_SERVER, port=config.EFFECTIVE_SERVER_PORT, use_reloader=((not app.PGADMIN_RUNTIME) and app.debug and os.environ.get("WERKZEUG_RUN_MAIN") is not None), threaded=config.THREADED_MODE) except IOError: app.logger.error("Error starting the app server: %s", sys.exc_info())
javascriptBundler.bundle() # Create the app! app = create_app() if config.SERVER_MODE: app.wsgi_app = ReverseProxied(app.wsgi_app) if config.DEBUG: app.debug = True else: app.debug = False # respond to JS if config.DEBUG: if javascriptBundler.report() == JsState.NONE: app.logger.error("Unable to generate javascript") app.logger.error( "To run the app ensure that yarn install command runs successfully" ) raise Exception("No generated javascript, aborting") # Start the web server. The port number should have already been set by the # runtime if we're running in desktop mode, otherwise we'll just use the # Flask default. PGADMIN_RUNTIME = False if 'PGADMIN_PORT' in globals(): app.logger.debug('Running under the desktop runtime, port: %s', globals()['PGADMIN_PORT']) server_port = int(globals()['PGADMIN_PORT']) PGADMIN_RUNTIME = True
javascriptBundler = JavascriptBundler() javascriptBundler.bundle() # Create the app! app = create_app() if config.SERVER_MODE: app.wsgi_app = ReverseProxied(app.wsgi_app) if config.DEBUG: app.debug = True else: app.debug = False # respond to JS if config.DEBUG and javascriptBundler.report() == JsState.NONE: app.logger.error( "Unable to generate javascript.\n" "To run the app ensure that yarn install command runs successfully") raise Exception("No generated javascript, aborting") # Start the web server. The port number should have already been set by the # runtime if we're running in desktop mode, otherwise we'll just use the # Flask default. PGADMIN_RUNTIME = False if 'PGADMIN_INT_PORT' in globals(): app.logger.debug('Running under the desktop runtime, port: %s', globals()['PGADMIN_INT_PORT']) server_port = int(globals()['PGADMIN_INT_PORT']) PGADMIN_RUNTIME = True elif 'PGADMIN_INT_PORT' in os.environ: