~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to build/lib/gozerbot/plugs/count.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Malcolm
  • Date: 2012-04-03 21:58:28 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120403215828-6mik0tzug5na93la
Tags: 0.99.1-2
* Removes logfiles on purge (Closes: #668767)
* Reverted location of installed files back to /usr/lib/gozerbot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# plugs/count.py
 
2
#
 
3
#
 
4
 
 
5
""" count number of items in result queue. """
 
6
 
 
7
__copyright__ = 'this file is in the public domain'
 
8
 
 
9
# gozerbot imports
 
10
from gozerbot.commands import cmnds
 
11
from gozerbot.utils.generic import waitforqueue
 
12
from gozerbot.examples import examples
 
13
from gozerbot.plughelp import plughelp
 
14
from gozerbot.tests import tests
 
15
 
 
16
plughelp.add('count', 'the count command counts the number of results in a \
 
17
pipeline')
 
18
 
 
19
def handle_count(bot, ievent):
 
20
 
 
21
    """ show nr of elements in result list. """
 
22
 
 
23
    if not ievent.inqueue:
 
24
        ievent.reply("use count in a pipeline")
 
25
        return
 
26
 
 
27
    result = waitforqueue(ievent.inqueue, 5)
 
28
    ievent.reply(str(len(result)))
 
29
 
 
30
cmnds.add('count', handle_count, ['USER', 'WEB', 'CLOUD'], threaded=True)
 
31
examples.add('count', 'count nr of items', 'todo | count')
 
32
tests.add('list | count')