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
def rename(self, name, overwrite=False, settings=settings): if name == self.name: return new_prj = self._manager.get_project(name) new_prj.create(overwrite) new_path = filepath.FilePath(new_prj.path) new_path.remove() self._path.moveTo(new_path) self._path = new_path if self == self._manager.current: settings.set("current_project", self.name) settings.VIRTUALBRICKS_HOME = self.path settings.store()
def test_create_cow(self): settings.set("qemupath", "/supercali") failureResultOf(self, self.disk._create_cow("name"), errors.BadConfigError) settings.set("qemupath", TEST_DATA_PATH) self.disk.image = ImageStub() def cb(ret): self.fail("cow created, callback called with %s" % ret) def eb(failure): failure.trap(RuntimeError) return self.disk._create_cow("1").addCallbacks(cb, eb)
def test_connected_erroronloop(self): self.plug._antiloop = True settings.set("erroronloop", False) result = [] self.plug.connected().addErrback(result.append) self.assertEqual(len(result), 1) result[0].trap(errors.LinkLoopError) self.assertEqual(0, len(self.log)) self.plug._antiloop = True settings.set("erroronloop", True) self.plug.connected().addErrback(result.append) self.assertEqual(len(result), 2) result[1].trap(errors.LinkLoopError) self.assertEqual(1, len(self.log)) self.plug.connected().addErrback(result.append) self.assertEqual(len(result), 3) result[2].trap(errors.NotConnectedError) self.assertEqual(1, len(self.log))
def do_set(self, name, value): if settings.has_option(name): settings.set(name, value) else: self.sendLine("No such option %s" % name)
def patch_settings(suite, **kwds): olds = dict((k, settings.get(k)) for k in kwds.iterkeys()) suite.addCleanup(restore_settings, olds) suite.patch(settings, "store", lambda: None) for k, v in kwds.iteritems(): settings.set(k, v)
def restore_settings(olds): for k, v in olds.iteritems(): settings.set(k, v)