def __setCaptureWorkdir(self):
        """ Open a file dialog for choosing the location of local hypervisor
        working directory
        """
        
        capture_default_working_directory = '.'
        if os.environ.has_key("TEMP"):
            capture_default_working_directory = os.environ["TEMP"]
        elif os.environ.has_key("TMP"):
            capture_default_working_directory = os.environ["TMP"]
        elif os.path.exists('/tmp'):
            capture_default_working_directory = unicode('/tmp')

        fb = fileBrowser(translate('UiConfig_PreferencesCapture', 'Local capture working directory'), directory=capture_default_working_directory, parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            path = os.path.normpath(path)
            self.CaptureWorkingDirectory.setText(path)
            
            if sys.platform.startswith('win'):
                try:
                    path.encode('ascii')
                except:
                    QtGui.QMessageBox.warning(globals.preferencesWindow, translate("Page_PreferencesCapture", "Capture directory"), translate("Page_PreferencesCapture", "The path you have selected should contains only ascii (English) characters. Dynamips (Cygwin DLL) doesn't support unicode on Windows!"))

            if not testIfWritableDir(path):
                QtGui.QMessageBox.critical(globals.preferencesWindow, translate("Page_PreferencesCapture", "Capture directory"), translate("Page_PreferencesCapture", "Capture directory must be writable!"))
    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!"))
Example #3
0
    def slotSelectQemuImgPath(self):
        """ Get a path to Qemu-img from the file system
        """

        path = fileBrowser('Qemu-img', directory='.', parent=globals.preferencesWindow).getFile()
        if path != None and path[0] != '':
            self.lineEditQemuImgPath.setText(os.path.normpath(path[0]))
Example #4
0
    def __setIOSPath(self):
    
        fb = fileBrowser(translate('UiConfig_PreferencesGeneral', 'IOS Directory'), parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            self.IOSPath.setText(os.path.normpath(path))
    def __importConfiguration(self):

        config_path = os.path.normpath(unicode(ConfDB().fileName()))
        (path,
         selected) = fileBrowser(translate("UiConfig_PreferencesGeneral",
                                           "Import configuration"),
                                 filter='INI file (*.ini);;All files (*.*)',
                                 directory=os.path.dirname(config_path),
                                 parent=globals.preferencesWindow).getFile()

        if path != None and path != '':
            path = os.path.normpath(path)
            try:
                shutil.copyfile(path, config_path)
            except (OSError, IOError), e:
                QtGui.QMessageBox.critical(
                    globals.preferencesWindow,
                    translate("UiConfig_PreferencesGeneral",
                              "Import configuration"),
                    translate("UiConfig_PreferencesGeneral",
                              "Cannot export configuration file: %s") %
                    e.strerror)
                return
            except shutil.Error, e:
                QtGui.QMessageBox.critical(
                    globals.preferencesWindow,
                    translate("UiConfig_PreferencesGeneral",
                              "Import configuration"),
                    translate("UiConfig_PreferencesGeneral", "%s") % e)
                return
    def __importConfiguration(self):

        config_path = os.path.normpath(unicode(ConfDB().fileName()))
        (path, selected) = fileBrowser(
            translate("UiConfig_PreferencesGeneral", "Import configuration"),
            filter="INI file (*.ini);;All files (*.*)",
            directory=os.path.dirname(config_path),
            parent=globals.preferencesWindow,
        ).getFile()

        if path != None and path != "":
            path = os.path.normpath(path)
            try:
                shutil.copyfile(path, config_path)
            except (OSError, IOError), e:
                QtGui.QMessageBox.critical(
                    globals.preferencesWindow,
                    translate("UiConfig_PreferencesGeneral", "Import configuration"),
                    translate("UiConfig_PreferencesGeneral", "Cannot export configuration file: %s") % e.strerror,
                )
                return
            except shutil.Error, e:
                QtGui.QMessageBox.critical(
                    globals.preferencesWindow,
                    translate("UiConfig_PreferencesGeneral", "Import configuration"),
                    translate("UiConfig_PreferencesGeneral", "%s") % e,
                )
                return
Example #7
0
    def slotSelectStartupConfigPath(self):
        """ Get a path to the Startup-config from the file system
        """

        path = fileBrowser('Startup-config', directory='.', parent=self).getFile()
        if path != None and path[0] != '':
            self.lineEditStartupConfig.setText(os.path.normpath(path[0]))
Example #8
0
    def slotSelectImage(self):
        """ Get a JunOS image from the file system
        """

        path = fileBrowser('JunOS image',  directory=globals.GApp.systconf['general'].ios_path, parent=globals.nodeConfiguratorWindow).getFile()
        if path != None and path[0] != '':
            self.lineEditImage.clear()
            self.lineEditImage.setText(os.path.normpath(path[0]))
Example #9
0
    def slotSelectASAInitrd(self):
        """ Get an ASA Initrd from the file system
        """

        path = fileBrowser('ASA Initrd', directory=globals.GApp.systconf['general'].ios_path, parent=globals.preferencesWindow).getFile()
        if path != None and path[0] != '':
            self.ASAInitrd.clear()
            self.ASAInitrd.setText(os.path.normpath(path[0]))
Example #10
0
    def slotSelectImage(self):
        """ Get a JunOS image from the file system
        """

        path = fileBrowser('JunOS image',  directory=globals.GApp.systconf['general'].ios_path, parent=globals.nodeConfiguratorWindow).getFile()
        if path != None and path[0] != '':
            self.lineEditImage.clear()
            self.lineEditImage.setText(os.path.normpath(path[0]))
Example #11
0
    def slotSelectQemuImage(self):
        """ Get a Qemu image from the file system
        """

        path = fileBrowser('Qemu image', directory=globals.GApp.systconf['general'].ios_path, parent=globals.preferencesWindow).getFile()
        if path != None and path[0] != '':
            self.QemuImage.clear()
            self.QemuImage.setText(os.path.normpath(path[0]))
Example #12
0
    def slotSelectIDSImage2(self):
        """ Get a IDS image (hdb) from the file system
        """

        path = fileBrowser('IDS image 2 (hdb)', directory=globals.GApp.systconf['general'].ios_path, parent=globals.preferencesWindow).getFile()
        if path != None and path[0] != '':
            self.IDSImage2.clear()
            self.IDSImage2.setText(os.path.normpath(path[0]))
Example #13
0
    def slotCallLibraryBrowser(self):
        """ Call a file system browser to select a library
        """
        fb = fileBrowser(translate('SymbolManagement', 'Library path'), directory=globals.GApp.systconf['general'].project_path, parent=self)
        (path, selected) = fb.getFile()

        if path is not None and path != '':
            self.lineEditLibrary.clear()
            self.lineEditLibrary.setText(os.path.normpath(path))
Example #14
0
    def slotSelectQemuWrapperWorkdir(self):
        """ Get a working directory for Qemuwrapper from the file system
        """
        
        fb = fileBrowser(translate('UiConfig_PreferencesQemu', 'Local Qemu working directory'), parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            self.lineEditQemuwrapperWorkdir.setText(os.path.normpath(path))
Example #15
0
    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 slotSelectVBoxWrapperPath(self):
        """ Get a path to VBoxwrapper from the file system
        """

        vboxwrapper_default_directory = '.'
        if sys.platform.startswith('darwin') and hasattr(sys, "frozen") and os.path.exists('../Resources/'):
            vboxwrapper_default_directory = '../Resources/'

        path = fileBrowser('VBoxwrapper', directory=vboxwrapper_default_directory, parent=globals.preferencesWindow).getFile()
        if path != None and path[0] != '':
            self.lineEditVBoxwrapperPath.setText(os.path.normpath(path[0]))
Example #17
0
    def slotSelectStartupConfigPath(self):
        """ Get a path to the Startup-config from the file system
        """

        if self.config_path and self.config_path != 'None':
            directory = os.path.dirname(self.config_path)
        else:
            directory = globals.GApp.systconf['general'].project_path

        path = fileBrowser('Startup-config', directory=directory, parent=self).getFile()
        if path != None and path[0] != '':
            self.lineEditStartupConfig.setText(os.path.normpath(path[0]))
Example #18
0
    def slotSelectStartupConfigPath(self):
        """ Get a path to the Startup-config from the file system
        """

        if self.config_path and self.config_path != 'None':
            directory = os.path.dirname(self.config_path)
        else:
            directory = globals.GApp.systconf['general'].project_path

        path = fileBrowser('Startup-config', directory=directory,
                           parent=self).getFile()
        if path != None and path[0] != '':
            self.lineEditStartupConfig.setText(os.path.normpath(path[0]))
Example #19
0
    def __setProjectDir(self):
        """ Open a file dialog for choosing the location of the project directory
        """

        fb = fileBrowser(translate('ProjectDialog', 'Project Directory'), globals.GApp.systconf['general'].project_path, parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            path = os.path.normpath(path)
            if os.path.realpath(path) != os.path.realpath(globals.GApp.systconf['general'].project_path):
                self.ProjectPath.setText(path + os.sep + self.ProjectName.text())
            else:
                self.ProjectPath.setText(path)
Example #20
0
    def slotWorkingDirectory(self):
        """ Get a working directory from the file system
        """

        path = fileBrowser(translate("IOSDialog", "Select a working directory"), parent=self).getDir()
        if path:
            self.lineEditWorkingDir.clear()
            self.lineEditWorkingDir.setText(os.path.normpath(path))

            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!"))
Example #21
0
    def slotWorkingDirectory(self):
        """ Get a working directory from the file system
        """

        path = fileBrowser(translate("IOSDialog", "Select a working directory"), parent=self).getDir()
        if path:
            self.lineEditWorkingDir.clear()
            self.lineEditWorkingDir.setText(os.path.normpath(path))

            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!"))
Example #22
0
    def __setDynamipsWorkdir(self):
        """ Open a file dialog for choosing the location of local hypervisor
        working directory
        """
        fb = fileBrowser(translate('UiConfig_PreferencesDynamips', 'Local hypervisor working directory'), parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            self.dynamips_workdir.setText(os.path.normpath(path))
            
            if sys.platform.startswith('win'):
                try:
                    path.encode('ascii')
                except:
                    QtGui.QMessageBox.warning(globals.preferencesWindow, translate("UiConfig_PreferencesDynamips", "Working directory"), translate("UiConfig_PreferencesDynamips", "The path you have selected should contains only ascii (English) characters. Dynamips (Cygwin DLL) doesn't support unicode on Windows!"))
Example #23
0
    def __setProjectDir(self):
        """ Open a file dialog for choosing the location of the projects directory
        """

        fb = fileBrowser(translate('ProjectDialog', 'Projects Directory'),
                         globals.GApp.systconf['general'].project_path,
                         parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            path = os.path.normpath(path)
            if os.path.realpath(path) != os.path.realpath(
                    globals.GApp.systconf['general'].project_path):
                self.ProjectPath.setText(path + os.sep +
                                         self.ProjectName.text())
            else:
                self.ProjectPath.setText(path)
    def __setIOSPath(self):

        ios_default_directory = "."
        if os.path.exists(globals.GApp.systconf["general"].ios_path):
            ios_default_directory = globals.GApp.systconf["general"].ios_path
        elif sys.platform.startswith("win") and os.environ.has_key("HOMEDRIVE") and os.environ.has_key("HOMEPATH"):
            ios_default_directory = os.environ["HOMEDRIVE"] + os.environ["HOMEPATH"]
        elif os.environ.has_key("HOME"):
            ios_default_directory = os.environ["HOME"]

        fb = fileBrowser(
            translate("UiConfig_PreferencesGeneral", "Images Directory"),
            directory=ios_default_directory,
            parent=globals.preferencesWindow,
        )
        path = fb.getDir()

        if path:
            self.IOSPath.setText(os.path.normpath(path))
Example #25
0
    def __setDynamipsWorkdir(self):
        """ Open a file dialog for choosing the location of local hypervisor
        working directory
        """

        dynamips_default_working_directory = '.'
        if os.environ.has_key("TEMP"):
            dynamips_default_working_directory = os.environ["TEMP"]
        elif os.environ.has_key("TMP"):
            dynamips_default_working_directory = os.environ["TMP"]
        elif os.path.exists('/tmp'):
            dynamips_default_working_directory = unicode('/tmp')

        fb = fileBrowser(translate('UiConfig_PreferencesDynamips',
                                   'Local hypervisor working directory'),
                         directory=dynamips_default_working_directory,
                         parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            self.dynamips_workdir.setText(os.path.normpath(path))

            if sys.platform.startswith('win'):
                try:
                    path.encode('ascii')
                except:
                    QtGui.QMessageBox.warning(
                        globals.preferencesWindow,
                        translate("UiConfig_PreferencesDynamips",
                                  "Working directory"),
                        translate(
                            "UiConfig_PreferencesDynamips",
                            "The path you have selected should contains only ascii (English) characters. Dynamips (Cygwin DLL) doesn't support unicode on Windows!"
                        ))

            if not testIfWritableDir(path):
                QtGui.QMessageBox.critical(
                    globals.preferencesWindow,
                    translate("UiConfig_PreferencesDynamips",
                              "Working directory"),
                    translate("UiConfig_PreferencesDynamips",
                              "Dynamips working directory must be writable!"))
    def __setIOSPath(self):

        ios_default_directory = '.'
        if os.path.exists(globals.GApp.systconf['general'].ios_path):
            ios_default_directory = globals.GApp.systconf['general'].ios_path
        elif sys.platform.startswith('win') and os.environ.has_key(
                "HOMEDRIVE") and os.environ.has_key("HOMEPATH"):
            ios_default_directory = os.environ["HOMEDRIVE"] + os.environ[
                "HOMEPATH"]
        elif os.environ.has_key("HOME"):
            ios_default_directory = os.environ["HOME"]

        fb = fileBrowser(translate('UiConfig_PreferencesGeneral',
                                   'Images Directory'),
                         directory=ios_default_directory,
                         parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            self.IOSPath.setText(os.path.normpath(path))
    def slotSelectVBoxWrapperWorkdir(self):
        """ Get a working directory for VBoxwrapper from the file system
        """

        vboxwrapper_default_working_directory = '.'
        if os.environ.has_key("TEMP"):
            vboxwrapper_default_working_directory = os.environ["TEMP"]
        elif os.environ.has_key("TMP"):
            vboxwrapper_default_working_directory = os.environ["TMP"]
        elif os.path.exists('/tmp'):
            vboxwrapper_default_working_directory = unicode('/tmp')

        fb = fileBrowser(translate('UiConfig_PreferencesVirtualBox', 'Local VirtualBox working directory'), directory=vboxwrapper_default_working_directory, parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            path = os.path.normpath(path)
            self.lineEditVBoxwrapperWorkdir.setText(path)

            if not testIfWritableDir(path):
                QtGui.QMessageBox.critical(globals.preferencesWindow, translate("UiConfig_PreferencesVirtualBox", "Working directory"), translate("UiConfig_PreferencesVirtualBox", "Vbox working directory must be writable!"))
Example #28
0
    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!"
                        ))
Example #29
0
    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)
Example #30
0
    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)
Example #31
0
    def __changePath(self):
        fb = fileBrowser(translate('UiConfig_PreferencesDeployementWizard', 'Deployement Wizard directory'), parent=globals.preferencesWindow)
        path = fb.getDir()

        if path:
            self.ProjectPath.setText(os.path.normpath(path))
Example #32
0
    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()
Example #33
0
    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()