def _configurationFile(self): if sys.platform.startswith("win"): filename = "gns3_gui.ini" else: filename = "gns3_gui.conf" directory = LocalConfig.configDirectory() return os.path.join(directory, filename)
def _okButtonClickedSlot(self): path, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Export debug file", None, "Zip file (*.zip)", "Zip file (*.zip)") if len(path) == 0: self.reject() return log.info("Export debug information to %s", path) try: with ZipFile(path, 'w') as zip: zip.writestr("debug.txt", self._getDebugData()) dir = LocalConfig.configDirectory() for filename in os.listdir(dir): path = os.path.join(dir, filename) if os.path.isfile(path): zip.write(path, filename) dir = self._project.filesDir() if dir: for filename in os.listdir(dir): path = os.path.join(dir, filename) if os.path.isfile(path): zip.write(path, filename) except OSError as e: QtWidgets.QMessageBox.critical(self, "Debug", "Can't export debug information: {}".format(str(e))) self.accept()
def _configurationFile(self): if sys.platform.startswith("win"): filename = "gns3_gui.ini" else: filename = "gns3_gui.conf" directory = LocalConfig.configDirectory() return os.path.join(directory, filename)
def main(): """ Entry point for GNS3 GUI. """ # Sometimes (for example at first launch) the OSX app service launcher add # an extra argument starting with -psn_. We filter it if sys.platform.startswith("darwin"): sys.argv = [a for a in sys.argv if not a.startswith("-psn_")] parser = argparse.ArgumentParser() parser.add_argument("project", help="load a GNS3 project (.gns3)", metavar="path", nargs="?") parser.add_argument("--version", help="show the version", action="version", version=__version__) parser.add_argument("--debug", help="print out debug messages", action="store_true", default=False) parser.add_argument("--config", help="Configuration file") options = parser.parse_args() exception_file_path = "exceptions.log" if options.config: LocalConfig.instance(config_file=options.config) else: LocalConfig.instance() if options.project: options.project = os.path.abspath(options.project) if hasattr(sys, "frozen"): # We add to the path where the OS search executable our binary location starting by GNS3 # packaged binary frozen_dir = os.path.dirname(os.path.abspath(sys.executable)) if sys.platform.startswith("darwin"): frozen_dirs = [ frozen_dir, os.path.normpath(os.path.join(frozen_dir, '..', 'Resources')) ] elif sys.platform.startswith("win"): frozen_dirs = [ frozen_dir, os.path.normpath(os.path.join(frozen_dir, 'dynamips')), os.path.normpath(os.path.join(frozen_dir, 'vpcs')) ] os.environ["PATH"] = os.pathsep.join(frozen_dirs) + os.pathsep + os.environ.get("PATH", "") if options.project: os.chdir(frozen_dir) def exceptionHook(exception, value, tb): if exception == KeyboardInterrupt: sys.exit(0) lines = traceback.format_exception(exception, value, tb) print("****** Exception detected, traceback information saved in {} ******".format(exception_file_path)) print("\nPLEASE REPORT ON https://www.gns3.com\n") print("".join(lines)) try: curdate = time.strftime("%d %b %Y %H:%M:%S") logfile = open(exception_file_path, "a", encoding="utf-8") logfile.write("=== GNS3 {} traceback on {} ===\n".format(__version__, curdate)) logfile.write("".join(lines)) logfile.close() except OSError as e: print("Could not save traceback to {}: {}".format(os.path.normpath(exception_file_path), e)) if not sys.stdout.isatty(): # if stdout is not a tty (redirected to the console view), # then print the exception on stderr too. print("".join(lines), file=sys.stderr) if exception is MemoryError: print("YOUR SYSTEM IS OUT OF MEMORY!") else: CrashReport.instance().captureException(exception, value, tb) # catch exceptions to write them in a file sys.excepthook = exceptionHook current_year = datetime.date.today().year print("GNS3 GUI version {}".format(__version__)) print("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) # we only support Python 3 version >= 3.4 if sys.version_info < (3, 4): raise SystemExit("Python 3.4 or higher is required") if parse_version(QtCore.QT_VERSION_STR) < parse_version("5.0.0"): raise SystemExit("Requirement is PyQt5 version 5.0.0 or higher, got version {}".format(QtCore.QT_VERSION_STR)) if parse_version(psutil.__version__) < parse_version("2.2.1"): raise SystemExit("Requirement is psutil version 2.2.1 or higher, got version {}".format(psutil.__version__)) # check for the correct locale # (UNIX/Linux only) locale_check() try: os.getcwd() except FileNotFoundError: log.critical("the current working directory doesn't exist") return # always use the INI format on Windows and OSX (because we don't like the registry and plist files) if sys.platform.startswith('win') or sys.platform.startswith('darwin'): QtCore.QSettings.setDefaultFormat(QtCore.QSettings.IniFormat) if sys.platform.startswith('win') and hasattr(sys, "frozen"): try: import win32console import win32con import win32gui except ImportError: raise SystemExit("Python for Windows extensions must be installed.") if not options.debug: try: # hide the console console_window = win32console.GetConsoleWindow() win32gui.ShowWindow(console_window, win32con.SW_HIDE) except win32console.error as e: print("warning: could not allocate console: {}".format(e)) global app app = Application(sys.argv) # save client logging info to a file logfile = os.path.join(LocalConfig.configDirectory(), "gns3_gui.log") # on debug enable logging to stdout if options.debug: root_logger = init_logger(logging.DEBUG, logfile) else: root_logger = init_logger(logging.INFO, logfile) # update the exception file path to have it in the same directory as the settings file. exception_file_path = os.path.join(LocalConfig.configDirectory(), exception_file_path) global mainwindow mainwindow = MainWindow() # On OSX we can receive the file to open from a system event # loadPath is smart and will load only if a path is present mainwindow.ready_signal.connect(lambda: mainwindow.loadPath(app.open_file_at_startup)) mainwindow.ready_signal.connect(lambda: mainwindow.loadPath(options.project)) app.file_open_signal.connect(lambda path: mainwindow.loadPath(path)) # Manage Ctrl + C or kill command def sigint_handler(*args): log.info("Signal received exiting the application") mainwindow.setSoftExit(False) app.closeAllWindows() orig_sigint = signal.signal(signal.SIGINT, sigint_handler) orig_sigterm = signal.signal(signal.SIGTERM, sigint_handler) mainwindow.show() exit_code = app.exec_() signal.signal(signal.SIGINT, orig_sigint) signal.signal(signal.SIGTERM, orig_sigterm) delattr(MainWindow, "_instance") # We force deleting the app object otherwise it's segfault on Fedora del app # We force a full garbage collect before exit # for unknow reason otherwise Qt Segfault on OSX in some # conditions import gc gc.collect() sys.exit(exit_code)
def main(): """ Entry point for GNS3 GUI. """ # Sometimes (for example at first launch) the OSX app service launcher add # an extra argument starting with -psn_. We filter it if sys.platform.startswith("darwin"): sys.argv = [a for a in sys.argv if not a.startswith("-psn_")] parser = argparse.ArgumentParser() parser.add_argument("project", help="load a GNS3 project (.gns3)", metavar="path", nargs="?") parser.add_argument("--version", help="show the version", action="version", version=__version__) parser.add_argument("--debug", help="print out debug messages", action="store_true", default=False) parser.add_argument("--config", help="Configuration file") options = parser.parse_args() exception_file_path = "exceptions.log" if options.config: LocalConfig.instance(config_file=options.config) else: LocalConfig.instance() if hasattr(sys, "frozen"): # We add to the path where the OS search executable our binary location starting by GNS3 # packaged binary frozen_dir = os.path.dirname(os.path.abspath(sys.executable)) if sys.platform.startswith("darwin"): frozen_dirs = [ frozen_dir, os.path.normpath(os.path.join(frozen_dir, '..', 'Resources')) ] elif sys.platform.startswith("win"): frozen_dirs = [ frozen_dir, os.path.normpath(os.path.join(frozen_dir, 'dynamips')), os.path.normpath(os.path.join(frozen_dir, 'vpcs')) ] os.environ["PATH"] = os.pathsep.join( frozen_dirs) + os.pathsep + os.environ.get("PATH", "") if options.project: options.project = os.path.abspath(options.project) os.chdir(frozen_dir) def exceptionHook(exception, value, tb): if exception == KeyboardInterrupt: sys.exit(0) lines = traceback.format_exception(exception, value, tb) print( "****** Exception detected, traceback information saved in {} ******" .format(exception_file_path)) print("\nPLEASE REPORT ON https://www.gns3.com\n") print("".join(lines)) try: curdate = time.strftime("%d %b %Y %H:%M:%S") logfile = open(exception_file_path, "a", encoding="utf-8") logfile.write("=== GNS3 {} traceback on {} ===\n".format( __version__, curdate)) logfile.write("".join(lines)) logfile.close() except OSError as e: print("Could not save traceback to {}: {}".format( os.path.normpath(exception_file_path), e)) if not sys.stdout.isatty(): # if stdout is not a tty (redirected to the console view), # then print the exception on stderr too. print("".join(lines), file=sys.stderr) if exception is MemoryError: print("YOUR SYSTEM IS OUT OF MEMORY!") else: CrashReport.instance().captureException(exception, value, tb) # catch exceptions to write them in a file sys.excepthook = exceptionHook current_year = datetime.date.today().year print("GNS3 GUI version {}".format(__version__)) print("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) # we only support Python 3 version >= 3.4 if sys.version_info < (3, 4): raise SystemExit("Python 3.4 or higher is required") def version(version_string): result = [] for i in re.split(r'[^0-9]', version_string): if len(i): result.append(int(i)) return result # 4.8.3 because of QSettings (http://pyqt.sourceforge.net/Docs/PyQt4/pyqt_qsettings.html) if DEFAULT_BINDING == "PyQt4" and version( QtCore.BINDING_VERSION_STR) < version("4.8.3"): raise SystemExit( "Requirement is PyQt version 4.8.3 or higher, got version {}". format(QtCore.BINDING_VERSION_STR)) if DEFAULT_BINDING == "PyQt5" and version( QtCore.BINDING_VERSION_STR) < version("5.0.0"): raise SystemExit( "Requirement is PyQt5 version 5.0.0 or higher, got version {}". format(QtCore.BINDING_VERSION_STR)) import psutil if version(psutil.__version__) < version("2.2.1"): raise SystemExit( "Requirement is psutil version 2.2.1 or higher, got version {}". format(psutil.__version__)) # check for the correct locale # (UNIX/Linux only) locale_check() try: os.getcwd() except FileNotFoundError: log.critical("the current working directory doesn't exist") return # always use the INI format on Windows and OSX (because we don't like the registry and plist files) if sys.platform.startswith('win') or sys.platform.startswith('darwin'): QtCore.QSettings.setDefaultFormat(QtCore.QSettings.IniFormat) if sys.platform.startswith('win') and hasattr(sys, "frozen"): try: import win32console import win32con import win32gui except ImportError: raise SystemExit( "Python for Windows extensions must be installed.") if not options.debug: try: # hide the console console_window = win32console.GetConsoleWindow() win32gui.ShowWindow(console_window, win32con.SW_HIDE) except win32console.error as e: print("warning: could not allocate console: {}".format(e)) global app app = Application(sys.argv) # save client logging info to a file logfile = os.path.join(LocalConfig.configDirectory(), "gns3_gui.log") # on debug enable logging to stdout if options.debug: root_logger = init_logger(logging.DEBUG, logfile) else: root_logger = init_logger(logging.INFO, logfile) # update the exception file path to have it in the same directory as the settings file. exception_file_path = os.path.join(LocalConfig.configDirectory(), exception_file_path) global mainwindow mainwindow = MainWindow() # On OSX we can receive the file to open from a system event # loadPath is smart and will load only if a path is present mainwindow.ready_signal.connect( lambda: mainwindow.loadPath(app.open_file_at_startup)) mainwindow.ready_signal.connect( lambda: mainwindow.loadPath(options.project)) app.file_open_signal.connect(lambda path: mainwindow.loadPath(path)) # Manage Ctrl + C or kill command def sigint_handler(*args): log.info("Signal received exiting the application") mainwindow.setSoftExit(False) app.closeAllWindows() signal.signal(signal.SIGINT, sigint_handler) signal.signal(signal.SIGTERM, sigint_handler) mainwindow.show() exit_code = app.exec_() delattr(MainWindow, "_instance") # We force a full garbage collect before exit # for unknow reason otherwise Qt Segfault on OSX in some # conditions import gc gc.collect() sys.exit(exit_code)
def _browseConfigurationDirectorySlot(self): """ Slot to open a file browser into the configuration directory """ QtGui.QDesktopServices.openUrl( QtCore.QUrl("file://" + LocalConfig.configDirectory()))
def _browseConfigurationDirectorySlot(self): """ Slot to open a file browser into the configuration directory """ QtGui.QDesktopServices.openUrl(QtCore.QUrl("file://" + LocalConfig.configDirectory()))