def getLastProject(self): if self.lastProjectPath is None: return None from netzob.Common.Project import Project project = Project.loadProject(self, self.lastProjectPath) return project
def projectsTreeviewSelection_changed_cb(self, selection): (model, treeiter) = selection.get_selected() if treeiter is not None: (projectPath, projectName) = self._getSelectedProject() self.log.debug("Selected project: '{0}' (path: {1})".format( projectName, projectPath)) self.selectedProject = Project.loadProject(self.workspace, projectPath) self._refreshProjectProperties() self.view.projectsDuplicateButton.set_sensitive(True) self.view.projectsDeleteButton.set_sensitive(True) self.view.projectsExportButton.set_sensitive(True) self.view.projectsConfigureButton.set_sensitive(True) else: self.selectedProject = None self._refreshProjectProperties() self.view.projectsDuplicateButton.set_sensitive(False) self.view.projectsDeleteButton.set_sensitive(False) self.view.projectsExportButton.set_sensitive(False) self.view.projectsConfigureButton.set_sensitive(False)
def importProjectAction(self, widget, data): chooser = gtk.FileChooserDialog(title=_("Export as"), action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) res = chooser.run() if res == gtk.RESPONSE_OK: fileName = chooser.get_filename() chooser.destroy() if os.path.isfile(fileName): idProject = str(uuid.uuid4()) # First we verify and create if necessary the directory of the project projectPath = "projects/" + idProject + "/" destPath = os.path.join(os.path.join(self.netzob.getCurrentWorkspace().getPath(), projectPath)) if not os.path.exists(destPath): logging.info("Creation of the directory " + destPath) os.mkdir(destPath) # Retrieving and storing of the config file try: destFile = os.path.join(destPath, Project.CONFIGURATION_FILENAME) shutil.copy(fileName, destFile) except IOError, e: logging.warn("Error when importing project: " + str(e)) return None project = Project.loadProject(self.netzob.getCurrentWorkspace(), destPath) project.setID(idProject) project.setName(_("Copy of {0}").format(project.getName())) project.setPath(projectPath) project.saveConfigFile(self.netzob.getCurrentWorkspace()) self.netzob.getCurrentWorkspace().referenceProject(project.getPath()) self.netzob.getCurrentWorkspace().saveConfigFile() NetzobInfoMessage(_("Project '{0}' correctly imported").format(project.getName())) self.update()
def getProjects(self): projects = [] for project_path in self.getProjectsPath(): from netzob.Common.Project import Project project = Project.loadProject(self, project_path) if project is not None: projects.append(project) return projects
def switchProjectAction(self, widget, projectPath): newProject = Project.loadProject(self.netzob.getCurrentWorkspace(), projectPath) if newProject == None: logging.error("Impossible to switch to requested project due to an error in the loading process.") return # Loading the project based on its name self.netzob.switchCurrentProject(newProject) self.update()
def test_workspaceParsing(self): # We first load the workspace workspace = Workspace.loadWorkspace(ResourcesConfiguration.getWorkspaceFile()) self.assertNotEqual(workspace, None) # Now we load all the project which are declared in for project_path in workspace.getProjectsPath() : project = Project.loadProject(workspace, project_path) if project != None : logging.info("The project " + project.getName() + " has been loaded !")
def switchProject(self, projectPath): """Change the current project with the project declared in file projectPath. If the loading is successful the view is updated. If a current project is already loaded, it offers to save pending modifications before changing. @param projectPath: the path to the project to load @type projectPath: str """ if projectPath is not None: logging.debug("Switch to the project declared in {0}".format(projectPath)) newProject = Project.loadProject(self.currentWorkspace, projectPath) if newProject is not None and self.closeCurrentProject(): self.currentProject = newProject # Emit a signal for toolbar upgrade self.getSignalsManager().emitSignal(SignalsManager.SIG_PROJECT_OPEN) self.view.currentProjectHasChanged() else: self.view.currentProjectHasChanged()