def __setDynamipsPath(self): """ Open a file dialog for choosing the location of dynamips executable """ dynamips_default_directory = '.' if sys.platform.startswith('darwin') and os.path.exists('../Resources/') and hasattr(sys, "frozen"): dynamips_default_directory = '../Resources/' fb = fileBrowser(translate('UiConfig_PreferencesDynamips', 'Dynamips binary'), directory=dynamips_default_directory, parent=globals.preferencesWindow) (path, selected) = fb.getFile() if path is not None and path != '': # test if we can open it if not testOpenFile(path): QtGui.QMessageBox.critical(globals.preferencesWindow, 'Dynamips path', translate("UiConfig_PreferencesDynamips", "Can't open file: %s") % path) return self.dynamips_path.clear() self.dynamips_path.setText(os.path.normpath(path)) if sys.platform.startswith('win'): try: path.encode('ascii') except: QtGui.QMessageBox.warning(globals.preferencesWindow, translate("UiConfig_PreferencesDynamips", "Dynamips path"), translate("UiConfig_PreferencesDynamips", "The path you have selected should contains only ascii (English) characters. Dynamips (Cygwin DLL) doesn't support unicode on Windows!"))
def slotSelectIOS(self): """ Get an IOS image file from the file system Insert platforms and models """ # get the path to the ios image path = fileBrowser(translate("IOSDialog", "Select an IOS image"), directory=globals.GApp.systconf['general'].ios_path, parent=self).getFile() if path != None and path[0] != '': path = os.path.normpath(path[0]) # test if we can open it if not testOpenFile(path): QtGui.QMessageBox.critical(self, translate("IOSDialog", "IOS Configuration"), unicode(translate("IOSDialog", "Can't open file: %s")) % path) return if sys.platform.startswith('win'): try: path.encode('ascii') except: QtGui.QMessageBox.warning(self, translate("IOSDialog", "IOS Configuration"), translate("IOSDialog", "The path you have selected should contains only ascii (English) characters. Dynamips (Cygwin DLL) doesn't support unicode on Windows!")) self.lineEditIOSImage.clear() self.lineEditIOSImage.setText(path) # basename doesn't work on Unix with Windows paths, so let's use this little trick image = path if not sys.platform.startswith('win') and image[1] == ":": image = image[2:] image = image.replace("\\", "/") # try to guess the platform platform = self._getIOSplatform(os.path.basename(image)) if platform == '2600': # force c2600 platform index = self.comboBoxPlatform.findText('c2600') if index != -1: self.comboBoxPlatform.setCurrentIndex(index) index = self.comboBoxChassis.findText('2621') if index != -1: self.comboBoxChassis.setCurrentIndex(index) self.spinBoxDefaultRAM.setValue(64) return if (platform != None): for platformname in PLATFORMS.keys(): # retrieve all chassis for this platform for chassis in PLATFORMS[platformname]: if platform == chassis: index = self.comboBoxPlatform.findText(platformname) if index != -1: self.comboBoxPlatform.setCurrentIndex(index) index = self.comboBoxChassis.findText(chassis) if index != -1: self.comboBoxChassis.setCurrentIndex(index) if DEFAULT_RAM.has_key(platformname): self.spinBoxDefaultRAM.setValue(DEFAULT_RAM[platformname]) break
def slotBaseConfig(self): """ Get an base config file from the file system """ # get the path to the ios configuration path = fileBrowser(translate("IOSDialog", "Select a Base configuration file"), directory=globals.GApp.systconf['general'].ios_path, parent=self).getFile() if path != None and path[0] != '': path = os.path.normpath(path[0]) # test if we can open it if not testOpenFile(path): QtGui.QMessageBox.critical(self, translate("IOSDialog", "IOS Configuration"), translate("IOSDialog", "Can't open file: %s") % path) return if sys.platform.startswith('win'): try: path.encode('ascii') except: QtGui.QMessageBox.warning(self, translate("IOSDialog", "IOS Configuration"), translate("IOSDialog", "The path you have selected should contains only ascii (English) characters. Dynamips (Cygwin DLL) doesn't support unicode on Windows!")) self.lineEditBaseConfig.clear() self.lineEditBaseConfig.setText(path)
def __setDynamipsPath(self): """ Open a file dialog for choosing the location of dynamips executable """ dynamips_default_directory = '.' if sys.platform.startswith('darwin') and os.path.exists( '../Resources/') and hasattr(sys, "frozen"): dynamips_default_directory = '../Resources/' fb = fileBrowser(translate('UiConfig_PreferencesDynamips', 'Dynamips binary'), directory=dynamips_default_directory, parent=globals.preferencesWindow) (path, selected) = fb.getFile() if path is not None and path != '': # test if we can open it if not testOpenFile(path): QtGui.QMessageBox.critical( globals.preferencesWindow, 'Dynamips path', translate("UiConfig_PreferencesDynamips", "Can't open file: %s") % path) return self.dynamips_path.clear() self.dynamips_path.setText(os.path.normpath(path)) if sys.platform.startswith('win'): try: path.encode('ascii') except: QtGui.QMessageBox.warning( globals.preferencesWindow, translate("UiConfig_PreferencesDynamips", "Dynamips path"), translate( "UiConfig_PreferencesDynamips", "The path you have selected should contains only ascii (English) characters. Dynamips (Cygwin DLL) doesn't support unicode on Windows!" ))
def slotSelectIOS(self): """ Get an IOS image file from the file system Insert platforms and models """ # get the path to the ios image path = fileBrowser(translate("IOSDialog", "Select an IOS image"), directory=globals.GApp.systconf['general'].ios_path, parent=self).getFile() if path != None and path[0] != '': path = os.path.normpath(path[0]) # test if we can open it if not testOpenFile(path): QtGui.QMessageBox.critical(self, translate("IOSDialog", "IOS Configuration"), translate("IOSDialog", "Can't open file: %s") % path) return if sys.platform.startswith('win'): try: path.encode('ascii') except: QtGui.QMessageBox.warning(self, translate("IOSDialog", "IOS Configuration"), translate("IOSDialog", "The path you have selected should contains only ascii (English) characters. Dynamips (Cygwin DLL) doesn't support unicode on Windows!")) self.lineEditIOSImage.clear() if os.path.basename(path).startswith("c7200p"): reply = QtGui.QMessageBox.warning(self, translate("IOSDialog", "IOS Image"), translate("IOSDialog", "This IOS image is for the c7200 platform with NPE-G2 and using it is not recommended.\nPlease use an IOS image that do not start with c7200p.")) try: if isIOScompressed(path): if path.endswith('.bin'): extracted_ios = path.rsplit(".bin")[0] + '.image' else: extracted_ios = path + '.image' reply = QtGui.QMessageBox.question(self, translate("IOSDialog", "IOS Image"), translate("IOSDialog", "The IOS image is compressed. Would you like to uncompress it?\nThis will create %s") % os.path.basename(extracted_ios), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes: if os.path.exists(extracted_ios): QtGui.QMessageBox.warning(self, translate("IOSDialog", "IOS Image"), translate("IOSDialog", "%s already exists, let's use it") % extracted_ios) path = extracted_ios else: try: uncompressIOS(path, extracted_ios) path = extracted_ios except: QtGui.QMessageBox.critical(self, translate("IOSDialog", "IOS Image"), translate("IOSDialog", "Sorry, impossible to extract the IOS image")) except: pass self.lineEditIOSImage.setText(path) # basename doesn't work on Unix with Windows paths, so let's use this little trick image = path if not sys.platform.startswith('win') and image[1] == ":": image = image[2:] image = image.replace("\\", "/") # try to guess the platform platform = self._getIOSplatform(os.path.basename(image)) if platform == '2600': # force c2600 platform index = self.comboBoxPlatform.findText('c2600') if index != -1: self.comboBoxPlatform.setCurrentIndex(index) index = self.comboBoxChassis.findText('2621') if index != -1: self.comboBoxChassis.setCurrentIndex(index) self.spinBoxDefaultRAM.setValue(64) return if (platform != None): for platformname in PLATFORMS.keys(): # retrieve all chassis for this platform for chassis in PLATFORMS[platformname]: if platform == chassis: index = self.comboBoxPlatform.findText(platformname) if index != -1: self.comboBoxPlatform.setCurrentIndex(index) index = self.comboBoxChassis.findText(chassis) if index != -1: self.comboBoxChassis.setCurrentIndex(index) if DEFAULT_RAM.has_key(platformname): self.spinBoxDefaultRAM.setValue(DEFAULT_RAM[platformname]) break self.lineEditIdlePC.clear()