def manage_removeZenPacks(self, ids=(), REQUEST=None): """ Uninstall the given zenpacks. Uninstall the zenpack egg. If not in development mode then also delete the egg from the filesystem. """ import Products.ZenUtils.ZenPackCmd as ZenPackCmd # avoid circular imports from Products.ZenMessaging.queuemessaging.schema import removeZenPackQueuesExchanges # see ZEN-2682 only allow one zenpack to be removed at a time. This is because you # can select a zenpack and its dependent. If the dependent is removed first # you will get an error removing the zenpack if len(ids) > 1: msg = 'You can only remove one zenpack at a time.' if REQUEST: messaging.IMessageSender(self).sendToBrowser( 'Error', msg, priority=messaging.WARNING) return self.callZenScreen(REQUEST) raise ZenPackDependentsException(msg) if not getattr(self.dmd, 'ZenPackManager'): msg = 'Your Zenoss database appears to be out of date. Try ' \ 'running zenmigrate to update.' if REQUEST: messaging.IMessageSender(self).sendToBrowser( 'Error', msg, priority=messaging.WARNING) return self.callZenScreen(REQUEST) from ZenPack import ZenPackNeedMigrateException raise ZenPackNeedMigrateException(msg) canRemove, dependents = ZenPackCmd.CanRemoveZenPacks(self.dmd, ids) if not canRemove: msg = 'The following ZenPacks depend on one or more of the ' + \ ' ZenPacks you are trying to remove: %s' % ','.join(dependents) if REQUEST: messaging.IMessageSender(self).sendToBrowser( 'Error', msg, priority=messaging.WARNING) return self.callZenScreen(REQUEST) from ZenPack import ZenPackDependentsException raise ZenPackDependentsException(msg) for zpId in ids: zp = self.packs._getOb(zpId, None) if zp: if zp.isEggPack(): ZenPackCmd.RemoveZenPack(self.dmd, zpId, skipDepsCheck=True) audit('UI.ZenPack.Remove', zpId) else: os.system('%s --remove %s' % (binPath('zenpack'), zpId)) self._p_jar.sync() removeZenPackQueuesExchanges(zp.path()) if REQUEST: return self.callZenScreen(REQUEST)
def manage_addZenPack(self, packId, REQUEST=None, devDir=''): """ Create a new zenpack on the filesystem with the given info. Install the pack. If REQUEST then render the REQUEST otherwise return the new zenpack. """ import Products.ZenUtils.ZenPackCmd as ZenPackCmd if not getattr(self.dmd, 'ZenPackManager'): msg = 'Your Zenoss database appears to be out of date. Try ' \ 'running zenmigrate to update.' if REQUEST: messaging.IMessageSender(self).sendToBrowser( 'Error', msg, priority=messaging.WARNING) return self.callZenScreen(REQUEST) from ZenPack import ZenPackNeedMigrateException raise ZenPackNeedMigrateException(msg) # Make sure a zenpack can be created with given info canCreate, msgOrId = ZenPackCmd.CanCreateZenPack(self, packId) if canCreate: packId = msgOrId else: if REQUEST: messaging.IMessageSender(self).sendToBrowser( 'Add ZenPack', msgOrId) return self.callZenScreen(REQUEST, redirect=False) from ZenPack import ZenPackException raise ZenPackException(msgOrId) if devDir == "": devDir = varPath("ZenPackSource") # Create it zpDir = ZenPackCmd.CreateZenPack(packId, devDir=devDir) # Install it zenPacks = ZenPackCmd.InstallEggAndZenPack(self.dmd, zpDir, link=True, forceRunExternal=True) zenPack = self.packs._getOb(packId, None) audit('UI.ZenPack.Create', packId) if REQUEST: if zenPack: return REQUEST['RESPONSE'].redirect( zenPack.getPrimaryUrlPath()) messaging.IMessageSender(self).sendToBrowser( 'Error', 'There was an error creating the ZenPack.', priority=messaging.WARNING) return self.callZenScreen(REQUEST) return zenPack
def writeSetupValues(self): """ Write appropriate values to the setup.py file """ import Products.ZenUtils.ZenPackCmd as ZenPackCmd if not self.isEggPack(): raise ZenPackException( 'Calling writeSetupValues on non-egg zenpack.') # I don't think we need to specify packages anymore now that we are # using find_packages() in setup.py packages = [] parts = self.id.split('.') for i in range(len(parts)): packages.append('.'.join(parts[:i + 1])) attrs = dict( NAME=self.id, VERSION=self.version, AUTHOR=self.author, LICENSE=self.license, NAMESPACE_PACKAGES=packages[:-1], PACKAGES=packages, INSTALL_REQUIRES=['%s%s' % d for d in self.dependencies.items()], COMPAT_ZENOSS_VERS=self.compatZenossVers, PREV_ZENPACK_NAME=self.prevZenPackName, ) ZenPackCmd.WriteSetup(self.eggPath('setup.py'), attrs)
def fetchZenPack(self, packName, packVersion=''): """ Retrieve the given zenpack from Zenoss.net and install. """ import Products.ZenUtils.ZenPackCmd as ZenPackCmd zp = ZenPackCmd.FetchAndInstallZenPack(self.dmd, packName, packVersion) if REQUEST: return REQUEST['RESPONSE'].redirect(zp.getPrimaryUrlPath()) return zp
def manage_uploadPack(self, znetProject, description, REQUEST=None): """ Create a new release of the given project. """ import Products.ZenUtils.ZenPackCmd as ZenPackCmd userSettings = self.dmd.ZenUsers.getUserSettings() ZenPackCmd.UploadZenPack(self.dmd, self.id, znetProject, description, userSettings.zenossNetUser, userSettings.zenossNetPassword) if REQUEST: messaging.IMessageSender(self).sendToBrowser( 'ZenPack Uploaded', 'ZenPack uploaded to Zenoss.net.') return self.callZenScreen(REQUEST)