def local_test(): # pragma: no cover """Run local test.""" import tempfile from anaconda_navigator.utils.qthelpers import qapplication from anaconda_navigator.utils.logs import setup_logger log_folder = tempfile.mkdtemp() log_filename = 'testlog.log' setup_logger(log_folder=log_folder, log_filename=log_filename) log_path = os.path.join(log_folder, log_filename) app = qapplication() widget_development = test_json_endpoint(dev=True) widget_development.show() widget_production = test_json_endpoint(dev=False) widget_production.show() ex = app.exec_() with open(log_path) as f: text = f.read() if "No JSON object could be decoded" in text: sys.exit(1) sys.exit(ex)
def start_app(options): # pragma: no cover """Main application entry point.""" # Setup logger setup_logger(options.log_level) # Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+ if PYQT5: sys.excepthook = except_hook # Clean old style logs clean_logs() global app app = qapplication(test_time=60) set_application_icon() load_fonts(app) signal.signal(signal.SIGINT, signal.SIG_DFL) # Create file lock lock = filelock.FileLock(LOCKFILE) try: load_pid = misc.load_pid() # This means a PSutil Access Denied error was raised if load_pid is False: msgbox = MessageBoxInformation( title="Anaconda Navigator Startup Error", text=( "Navigator failed to start due to an incorrect shutdown. " "<br><br>" "We were unable to remove the pid & lock files. " "Please manually remove the following files and restart " "Anaconda Navigator:<br><ul>" "<li><pre>{}</pre></li><li><pre>{}</pre></li></ul>" "".format(LOCKFILE, PIDFILE))) sys.exit(msgbox.exec_()) elif load_pid is None: # A stale lock might be around misc.remove_lock() with lock.acquire(timeout=3.0): # timeout in seconds misc.save_pid() splash = SplashScreen() splash.show_message("Initializing...") window = run_app(splash) app.window = window event_eater = EventEater(app) app.installEventFilter(event_eater) sys.exit(app.exec_()) except filelock.Timeout: msgbox = MessageBoxInformation(title="Anaconda Navigator Information", text=("There is an instance of " "Anaconda Navigator already " "running.")) sys.exit(msgbox.exec_())
def loggerbot(qtbot, tmpfile): temp_log_folder = os.path.dirname(tmpfile) temp_log_filename = os.path.basename(tmpfile + '.log') setup_logger(log_level=logging.WARNING, log_folder=temp_log_folder, log_filename=temp_log_filename) logger.warning(TEST_TEXT) logger.warning(TEST_TEXT_EXTRA) widget = LogViewerDialog(log_folder=temp_log_folder, log_filename=temp_log_filename) widget.show() qtbot.addWidget(widget) return qtbot, widget
def start_app(options): # pragma: no cover """Main application entry point.""" # Setup logger setup_logger(options.log_level) # Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+ if PYQT5: sys.excepthook = except_hook # Clean old style logs clean_logs() global app app = qapplication(test_time=60) set_application_icon() load_fonts(app) signal.signal(signal.SIGINT, signal.SIG_DFL) # Create file lock lock = filelock.FileLock(LOCKFILE) try: if misc.load_pid() is None: # A stale lock might be around misc.remove_lock() with lock.acquire(timeout=3.0): # timeout in seconds misc.save_pid() splash = SplashScreen() splash.show_message("Initializing...") window = run_app(splash) app.window = window event_eater = EventEater(app) app.installEventFilter(event_eater) sys.exit(app.exec_()) except filelock.Timeout: msgbox = MessageBoxInformation( title="Anaconda Navigator Information", text=( "There is an instance of " "Anaconda Navigator already " "running." ) ) sys.exit(msgbox.exec_())