コード例 #1
0
ファイル: qmanager.py プロジェクト: tekmans/mmc
    def _replyToQuery(self, ctx, query, bool = None):
        raise "DON'T USE _replyToQuery!!!"
        ret = self.__recursive_query(ctx, query)

        values = {}
        values_neg = {}

        # TODO does not seems to work...
        #['AND', [['1', 'dyngroup', 'groupname', 'test']]]
        for qid, module, criterion, value in query:
            val, neg = self._getPluginReplyToQuery(
                ctx,
                self.queryablePlugins[module],
                [criterion, value]
            )
            values[str(qid)] = [val, neg]

        self.logger.debug(values)

        br = BoolRequest()
        if bool == None or bool == '' or bool == 0 or bool == '0':
            bool = 'AND('+','.join(map(lambda a:a[0][0], values))+')'


        all = ComputerManager().getComputersList(ctx)
        #all = ComputerManager().getRestrictedComputersList(ctx, 0, 50)
        # for the moment everything is based on names... should be changed into uuids
        #all = map(lambda a: a[1]['cn'][0], all.values())
        all = all.keys()
        values['A'] = [all, True]

        bool = 'AND(A, '+bool+')'

        br.parse(bool)
        if bool == None or not br.isValid(): # no bool specified = only AND
            if len(values.keys()) > 0:
                retour = values.pop()
                for val in values:
                    neg = val[1]
                    val = val[0]
                    if neg:
                        retour = filter(lambda a,val=val:a in val, retour)
                    else:
                        retour = filter(lambda a,val=val:a not in val, retour)

                return retour
            else:
                return [] # TODO : when plugged on Machines : should return : Machine - values_neg
        else:
            retour = br.merge(values)
            return retour[0]
コード例 #2
0
ファイル: qmanager.py プロジェクト: gnumaniac/pulse
    def _replyToQuery(self, ctx, query, bool = None):
        raise "DON'T USE _replyToQuery!!!"
        self.__recursive_query(ctx, query)

        values = {}

        # TODO does not seems to work...
        #['AND', [['1', 'dyngroup', 'groupname', 'test']]]
        for qid, module, criterion, value in query:
            val, neg = self._getPluginReplyToQuery(
                ctx,
                self.queryablePlugins[module],
                [criterion, value]
            )
            values[str(qid)] = [val, neg]

        self.logger.debug(values)

        br = BoolRequest()
        if bool == None or bool == '' or bool == 0 or bool == '0':
            bool = 'AND('+','.join(map(lambda a:a[0][0], values))+')'


        all = ComputerManager().getComputersList(ctx)
        #all = ComputerManager().getRestrictedComputersList(ctx, 0, 50)
        # for the moment everything is based on names... should be changed into uuids
        #all = map(lambda a: a[1]['cn'][0], all.values())
        all = all.keys()
        values['A'] = [all, True]

        bool = 'AND(A, '+bool+')'

        br.parse(bool)
        if bool == None or not br.isValid(): # no bool specified = only AND
            if len(values.keys()) > 0:
                retour = values.pop()
                for val in values:
                    neg = val[1]
                    val = val[0]
                    if neg:
                        retour = filter(lambda a,val=val:a in val, retour)
                    else:
                        retour = filter(lambda a,val=val:a not in val, retour)

                return retour
            else:
                return [] # TODO : when plugged on Machines : should return : Machine - values_neg
        else:
            retour = br.merge(values)
            return retour[0]