Esempio n. 1
0
    def open(self, factory, settings=settings):
        if self._manager.current == self:
            return
        if not self.exists():
            raise errors.ProjectNotExistsError(self.name)
        self.close(factory, settings)
        logger.debug(open_project, name=self.name)

        # save the old setting parameters
        # Bug #1410679
        old_proj = settings.get("current_project")
        old_vbhome = settings.VIRTUALBRICKS_HOME
        # save new setting parameters
        # Bug #1410679
        settings.set("current_project", self.name)
        settings.VIRTUALBRICKS_HOME = self.path
        settings.store()

        try:
            configfile.restore(factory, self._project.path)
        except EnvironmentError as e:
            # if an exception is raised then revert settings to the
            # default values
            # Bug #1410679
            settings.set("current_project", old_proj)
            settings.VIRTUALBRICKS_HOME = old_vbhome
            settings.store()
            if e.errno in (errno.ENOENT, errno.ENOTDIR):
                raise errors.ProjectNotExistsError(self.name)
            raise
        # if an exception is raised, this value is not changed, i.e. it
        # is the default
        self._manager.current = self
        return self
Esempio n. 2
0
 def setUp(self):
     self.factory = stubs.Factory()
     fp = filepath.FilePath(self.mktemp())
     self.image = self.mktemp()
     filepath.FilePath(self.image).touch()
     fp.setContent(OLD_CONFIG_FILE.replace("@@IMAGEPATH@@", self.image, 1))
     configfile.restore(self.factory, fp)