Example #1
0
    def search(self, irc, msg, args, user, optlist, glob):
        """[--{regexp} <value>] [--sent] [<glob>]

        Searches your received notes for ones matching <glob>.  If --regexp is
        given, its associated value is taken as a regexp and matched against
        the notes.  If --sent is specified, only search sent notes.
        """
        criteria = []
        def to(note):
            return note.to == user.id
        def frm(note):
            return note.frm == user.id
        own = to
        for (option, arg) in optlist:
            if option == 'regexp':
                criteria.append(lambda x: commands.regexp_wrapper(x, reobj=arg, 
                        timeout=0.1, plugin_name = self.name(), fcn_name='search'))
            elif option == 'sent':
                own = frm
        if glob:
            glob = utils.python.glob2re(glob)
            criteria.append(re.compile(glob).search)
        def match(note):
            for p in criteria:
                if not p(note.text):
                    return False
            return True
        notes = list(self.db.select(lambda n: match(n) and own(n)))
        if not notes:
            irc.reply('No matching notes were found.')
        else:
            utils.sortBy(operator.attrgetter('id'), notes)
            ids = [self._formatNoteId(msg, note) for note in notes]
            ids = self._condense(ids)
            irc.reply(format('%L', ids))
Example #2
0
    def search(self, irc, msg, args, user, optlist, globs):
        """[--{regexp} <value>] [<glob> <glob> ...]

        Searches your todos for tasks matching <glob>.  If --regexp is given,
        its associated value is taken as a regexp and matched against the
        tasks.
        """
        if not optlist and not globs:
            raise callbacks.ArgumentError
        criteria = []
        for (option, arg) in optlist:
            if option == 'regexp':
                criteria.append(
                    lambda x: commands.regexp_wrapper(x,
                                                      reobj=arg,
                                                      timeout=0.1,
                                                      plugin_name=self.name(),
                                                      fcn_name='search'))
                criteria.append(arg.search)
        for glob in globs:
            glob = utils.python.glob2re(glob)
            criteria.append(re.compile(glob).search)
        try:
            tasks = self.db.select(user.id, criteria)
            L = [format('#%i: %s', t.id, self._shrink(t.task)) for t in tasks]
            irc.reply(format('%L', L))
        except dbi.NoRecordError:
            irc.reply(_('No tasks matched that query.'))
Example #3
0
    def search(self, irc, msg, args, user, optlist, glob):
        """[--{regexp} <value>] [--sent] [<glob>]

        Searches your received notes for ones matching <glob>.  If --regexp is
        given, its associated value is taken as a regexp and matched against
        the notes.  If --sent is specified, only search sent notes.
        """
        criteria = []
        def to(note):
            return note.to == user.id
        def frm(note):
            return note.frm == user.id
        own = to
        for (option, arg) in optlist:
            if option == 'regexp':
                criteria.append(lambda x: commands.regexp_wrapper(x, reobj=arg, 
                        timeout=0.1, plugin_name = self.name(), fcn_name='search'))
            elif option == 'sent':
                own = frm
        if glob:
            glob = utils.python.glob2re(glob)
            criteria.append(re.compile(glob).search)
        def match(note):
            for p in criteria:
                if not p(note.text):
                    return False
            return True
        notes = list(self.db.select(lambda n: match(n) and own(n)))
        if not notes:
            irc.reply('No matching notes were found.')
        else:
            utils.sortBy(operator.attrgetter('id'), notes)
            ids = [self._formatNoteId(msg, note) for note in notes]
            ids = self._condense(ids)
            irc.reply(format('%L', ids))
Example #4
0
    def search(self, irc, msg, args, channel, optlist, glob):
        """[<channel>] [--{regexp,by} <value>] [<glob>]

        Searches for $types matching the criteria given.
        """
        predicates = []
        def p(record):
            for predicate in predicates:
                if not predicate(record):
                    return False
            return True

        for (opt, arg) in optlist:
            if opt == 'by':
                predicates.append(lambda r, arg=arg: r.by == arg.id)
            elif opt == 'regexp':
                predicates.append(lambda x: commands.regexp_wrapper(x.text, reobj=arg, 
                        timeout=0.1, plugin_name = self.name(), fcn_name='search'))
                #predicates.append(lambda r, arg=arg: arg.search(r.text))
        if glob:
            def globP(r, glob=glob.lower()):
                return fnmatch.fnmatch(r.text.lower(), glob)
            predicates.append(globP)
        L = []
        for record in self.db.select(channel, p):
            L.append(self.searchSerializeRecord(record))
        if L:
            L.sort()
            irc.reply(format('%s found: %L', len(L), L))
        else:
            what = self.name().lower()
            irc.reply(format('No matching %p were found.', what))
Example #5
0
    def search(self, irc, msg, args, channel, optlist, glob):
        """[<channel>] [--{regexp,by} <value>] [<glob>]

        Searches for $types matching the criteria given.
        """
        predicates = []

        def p(record):
            for predicate in predicates:
                if not predicate(record):
                    return False
            return True

        for (opt, arg) in optlist:
            if opt == 'by':
                predicates.append(lambda r, arg=arg: r.by == arg.id)
            elif opt == 'regexp':
                predicates.append(
                    lambda x: commands.regexp_wrapper(x.text,
                                                      reobj=arg,
                                                      timeout=0.1,
                                                      plugin_name=self.name(),
                                                      fcn_name='search'))
                #predicates.append(lambda r, arg=arg: arg.search(r.text))
        if glob:

            def globP(r, glob=glob.lower()):
                return fnmatch.fnmatch(r.text.lower(), glob)

            predicates.append(globP)
        L = []
        for record in self.db.select(channel, p):
            L.append(self.searchSerializeRecord(record))
        if L:
            L.sort()
            irc.reply(format('%s found: %L', len(L), L))
        else:
            what = self.name().lower()
            irc.reply(format('No matching %p were found.', what))
Example #6
0
    def search(self, irc, msg, args, user, optlist, globs):
        """[--{regexp} <value>] [<glob> <glob> ...]

        Searches your todos for tasks matching <glob>.  If --regexp is given,
        its associated value is taken as a regexp and matched against the
        tasks.
        """
        if not optlist and not globs:
            raise callbacks.ArgumentError
        criteria = []
        for (option, arg) in optlist:
            if option == 'regexp':
                criteria.append(lambda x: commands.regexp_wrapper(x, reobj=arg, 
                        timeout=0.1, plugin_name = self.name(), fcn_name='search'))
                criteria.append(arg.search)
        for glob in globs:
            glob = utils.python.glob2re(glob)
            criteria.append(re.compile(glob).search)
        try:
            tasks = self.db.select(user.id, criteria)
            L = [format('#%i: %s', t.id, self._shrink(t.task)) for t in tasks]
            irc.reply(format('%L', L))
        except dbi.NoRecordError:
            irc.reply(_('No tasks matched that query.'))