Example #1
0
def InstallEggAndZenPack(dmd,
                         eggPath,
                         link=False,
                         filesOnly=False,
                         sendEvent=True,
                         previousVersion=None,
                         forceRunExternal=False,
                         fromUI=False,
                         serviceId=None,
                         ignoreServiceInstall=False):
    """
    Installs the given egg, instantiates the ZenPack, installs in
    dmd.ZenPackManager.packs, and runs the zenpacks's install method.
    Returns a list of ZenPacks that were installed.
    """
    zenPacks = []
    nonCriticalErrorEncountered = False
    with paused(onIndexingEvent):
        try:
            zpDists = InstallEgg(dmd, eggPath, link=link)
            for d in zpDists:
                try:
                    zp = InstallDistAsZenPack(
                        dmd,
                        d,
                        eggPath,
                        link,
                        filesOnly=filesOnly,
                        previousVersion=previousVersion,
                        forceRunExternal=forceRunExternal,
                        fromUI=fromUI,
                        serviceId=serviceId,
                        ignoreServiceInstall=ignoreServiceInstall)
                    zenPacks.append(zp)
                    audit('Shell.ZenPack.Install', zp.id)
                except NonCriticalInstallError, ex:
                    nonCriticalErrorEncountered = True
                    if sendEvent:
                        ZPEvent(dmd, 3, ex.message)
        except Exception as e:
            # Get that exception out there in case it gets blown away by ZPEvent
            log.exception("Error installing ZenPack %s" % eggPath)
            if sendEvent:
                ZPEvent(dmd, SEVERITY_ERROR,
                        'Error installing ZenPack %s' % eggPath,
                        '%s: %s' % sys.exc_info()[:2])
            # Don't just raise, because if ZPEvent blew away exception context
            # it'll be None, which is bad. This manipulates the stack to look like
            # this is the source of the exception, but we logged it above so no
            # info is lost.
            raise e
    transaction.commit()
    if sendEvent:
        zenPackIds = [zp.id for zp in zenPacks]
        if zenPackIds:
            ZPEvent(dmd, 2, 'Installed ZenPacks %s' % ','.join(zenPackIds))
        elif not nonCriticalErrorEncountered:
            ZPEvent(dmd, SEVERITY_ERROR, 'Unable to install %s' % eggPath)
    return zenPacks
def InstallEggAndZenPack(
    dmd,
    eggPath,
    link=False,
    filesOnly=False,
    sendEvent=True,
    previousVersion=None,
    forceRunExternal=False,
    fromUI=False,
):
    """
    Installs the given egg, instantiates the ZenPack, installs in
    dmd.ZenPackManager.packs, and runs the zenpacks's install method.
    Returns a list of ZenPacks that were installed.
    """
    zenPacks = []
    nonCriticalErrorEncountered = False
    with paused(onIndexingEvent):
        try:
            zpDists = InstallEgg(dmd, eggPath, link=link)
            for d in zpDists:
                try:
                    zp = InstallDistAsZenPack(
                        dmd,
                        d,
                        eggPath,
                        link,
                        filesOnly=filesOnly,
                        previousVersion=previousVersion,
                        forceRunExternal=forceRunExternal,
                        fromUI=fromUI,
                    )
                    zenPacks.append(zp)
                except NonCriticalInstallError, ex:
                    nonCriticalErrorEncountered = True
                    if sendEvent:
                        ZPEvent(dmd, 3, ex.message)
        except Exception as e:
            # Get that exception out there in case it gets blown away by ZPEvent
            log.exception("Error installing ZenPack %s" % eggPath)
            if sendEvent:
                ZPEvent(dmd, SEVERITY_ERROR, "Error installing ZenPack %s" % eggPath, "%s: %s" % sys.exc_info()[:2])
            # Don't just raise, because if ZPEvent blew away exception context
            # it'll be None, which is bad. This manipulates the stack to look like
            # this is the source of the exception, but we logged it above so no
            # info is lost.
            raise e
    transaction.commit()
    if sendEvent:
        zenPackIds = [zp.id for zp in zenPacks]
        if zenPackIds:
            ZPEvent(dmd, 2, "Installed ZenPacks %s" % ",".join(zenPackIds))
        elif not nonCriticalErrorEncountered:
            ZPEvent(dmd, SEVERITY_ERROR, "Unable to install %s" % eggPath)
    return zenPacks
    def test_pauser(self):
        SEEN = []
        handler = SEEN.append

        provideHandler(handler, (MyEvent,))
        notify(MyEvent())
        self.assertEquals(1, len(SEEN))
        with paused(handler):
            notify(MyEvent())
            self.assertEquals(1, len(SEEN))
        self.assertEquals(2, len(SEEN))
        notify(MyEvent())
        self.assertEquals(3, len(SEEN))
Example #4
0
    def test_pauser(self):
        SEEN = []
        handler = SEEN.append

        provideHandler(handler, (MyEvent, ))
        notify(MyEvent())
        self.assertEquals(1, len(SEEN))
        with paused(handler):
            notify(MyEvent())
            self.assertEquals(1, len(SEEN))
        self.assertEquals(2, len(SEEN))
        notify(MyEvent())
        self.assertEquals(3, len(SEEN))