def test_properOrphaning(self): """ If two installed items both depend on a third, it should be removed as soon as both installed items are removed, but no sooner. """ foo = Kitchen(store=self.store) e = Toaster(store=self.store) dependency.installOn(e, foo) ps = self.store.findUnique(PowerStrip) bb = self.store.findUnique(Breadbox) f = Blender(store=self.store) dependency.installOn(f, foo) self.assertEquals(list(self.store.query(PowerStrip)), [ps]) #XXX does ordering matter? self.assertEquals(set(dependency.installedDependents(ps, foo)), set([e, f])) self.assertEquals(set(dependency.installedRequirements(e, foo)), set([bb, ps])) self.assertEquals(list(dependency.installedRequirements(f, foo)), [ps]) dependency.uninstallFrom(e, foo) self.assertEquals(dependency.installedOn(ps), foo) dependency.uninstallFrom(f, foo) self.assertEquals(dependency.installedOn(ps), None)
def upgradeParentHook3to4(old): """ Copy C{loginAccount} to C{subStore} and remove the installation marker. """ new = old.upgradeVersion(old.typeName, 3, 4, subStore=old.loginAccount) uninstallFrom(new, new.store) return new
def uninstall(self): """ Called when uninstalled from the user store. Uninstalls all my powerups. """ for item in self.items: uninstallFrom(item, self.store) self._items = []
def upgradeParentHook3to4(old): """ Copy C{loginAccount} to C{subStore} and remove the installation marker. """ new = old.upgradeVersion( old.typeName, 3, 4, subStore=old.loginAccount) uninstallFrom(new, new.store) return new
def postOptions(self): store = self.getStore() fact = store.findUnique(IRCBotFactoryFactory) svc = store.findUnique(IRCBotService, AND(IRCBotService.serviceID == self['id'], IRCBotService.factory == fact)); uninstallFrom(svc, store)
def postOptions(self): store = self.getStore() fact = store.findUnique(IRCBotFactoryFactory) svc = store.findUnique( IRCBotService, AND(IRCBotService.serviceID == self['id'], IRCBotService.factory == fact)) uninstallFrom(svc, store)
def test_basicUninstall(self): """ Ensure that uninstallation removes the adapter from the former install target and all orphaned dependencies. """ foo = Kitchen(store=self.store) e = Toaster(store=self.store) dependency.installOn(e, foo) dependency.uninstallFrom(e, foo) self.assertEqual(dependency.installedOn(e), None) self.assertEqual(dependency.installedOn(e.powerStrip), None)
def test_callbacks(self): """ 'installed' and 'uninstalled' callbacks should fire on install/uninstall. """ foo = Kitchen(store=self.store) e = Toaster(store=self.store) self.installCallbackCalled = False e.callback = lambda _: setattr(self, 'installCallbackCalled', True) dependency.installOn(e, foo) self.failUnless(self.installCallbackCalled) self.uninstallCallbackCalled = False e.callback = lambda _: setattr(self, 'uninstallCallbackCalled', True) dependency.uninstallFrom(e, foo) self.failUnless(self.uninstallCallbackCalled)
def test_explicitInstall(self): """ If an item is explicitly installed, it should not be implicitly uninstalled. Also, dependsOn attributes should be filled in properly even if a dependent item is not installed automatically. """ foo = Kitchen(store=self.store) ps = PowerStrip(store=self.store) dependency.installOn(ps, foo) e = Toaster(store=self.store) dependency.installOn(e, foo) self.assertEqual(e.powerStrip, ps) dependency.uninstallFrom(e, foo) self.assertEquals(dependency.installedOn(ps), foo)
def test_powerupInterfaces(self): """ Make sure interfaces are powered up and down properly. """ foo = Kitchen(store=self.store) e = Toaster(store=self.store) f = Blender(store=self.store) dependency.installOn(e, foo) dependency.installOn(f, foo) self.assertEquals(IAppliance(foo), e) self.assertEquals(IBreadConsumer(foo), e) dependency.uninstallFrom(e, foo) self.assertEquals(IAppliance(foo), f) dependency.uninstallFrom(f, foo) self.assertRaises(TypeError, IAppliance, foo)
def test_recursiveUninstall(self): """ Removal of items should recursively remove orphaned dependencies. """ foo = Kitchen(store=self.store) ic = IceCrusher(store=self.store) dependency.installOn(ic, foo) blender = self.store.findUnique(Blender) ps = self.store.findUnique(PowerStrip) dependency.uninstallFrom(ic, foo) self.failIf(dependency.installedOn(blender)) self.failIf(dependency.installedOn(ps)) self.failIf(dependency.installedOn(ic))
import sys from axiom.store import Store from axiom.dependency import uninstallFrom from eridanus.bot import IRCBotService db = Store(sys.argv[1]) for svc in db.query(IRCBotService): uninstallFrom(svc, db)
def _makeSiteConfiguration(currentVersion, oldSite, couldHavePorts): from xmantissa.publicweb import AnonymousSite newSite = oldSite.upgradeVersion( 'mantissa_web_powerup', currentVersion, 6, hitCount=oldSite.hitCount) if newSite.store.parent is not None: return newSite # SiteConfiguration dependsOn LoginSystem. LoginSystem was probably # installed by the mantissa axiomatic command. During the dependency # system conversion, that command was changed to use installOn on the # LoginSystem. However, no upgrader was supplied to create the new # dependency state. Consequently, there may be none. Consequently, a new # LoginSystem will be created if an item which dependsOn LoginSystem is # installed. This would be bad. So, set up the necessary dependency state # here, before instantiating SiteConfiguration. -exarkun # Addendum: it is almost certainly the case that there are not legitimate # configurations which lack a LoginSystem. However, a large number of # database upgrade tests construct unrealistic databases. One aspect of # the unrealism is that they lack a LoginSystem. Therefore, rather than # changing all the bogus stubs and regenerating the stubs, I will just # support the case where LoginSystem is missing. However, note that a # LoginSystem upgrader may invalidate this check and result in a duplicate # being created anyway. -exarkun loginSystem = oldSite.store.findUnique(LoginSystem, default=None) if loginSystem is not None and installedOn(loginSystem) is None: installOn(loginSystem, oldSite.store) uninstallFrom(oldSite.store, oldSite) site = SiteConfiguration( store=oldSite.store, httpLog=oldSite.store.filesdir.child('httpd.log'), hostname=getattr(oldSite, "hostname", None) or u"localhost") installOn(site, site.store) anonymousAvatar = AnonymousSite(store=oldSite.store) installOn(anonymousAvatar, oldSite.store) if couldHavePorts: for tcp in site.store.query(TCPPort, TCPPort.factory == oldSite): tcp.factory = site for ssl in site.store.query(SSLPort, SSLPort.factory == oldSite): ssl.factory = site else: if oldSite.portNumber is not None: port = TCPPort( store=oldSite.store, portNumber=oldSite.portNumber, factory=site) installOn(port, oldSite.store) securePortNumber = oldSite.securePortNumber certificateFile = oldSite.certificateFile if securePortNumber is not None and certificateFile: oldCertPath = site.store.dbdir.preauthChild(certificateFile) newCertPath = site.store.newFilePath('server.pem') oldCertPath.moveTo(newCertPath) port = SSLPort( store=site.store, portNumber=oldSite.securePortNumber, certificatePath=newCertPath, factory=site) installOn(port, site.store) newSite.deleteFromStore()