~ubuntu-branches/ubuntu/quantal/gozerbot/quantal

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2010-09-29 18:20:02 UTC
  • mfrom: (3.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100929182002-gi532gnem1vlu6jy
Tags: 0.9.1.3-5
Added python2.5 build dependency. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# plugs/tail.py
 
2
#
 
3
#
 
4
 
 
5
""" tail bot results. """
 
6
 
 
7
__copyright__ = 'this file is in the public domain'
 
8
 
 
9
# gozerbot imports
 
10
from gozerbot.utils.generic import waitforqueue
 
11
from gozerbot.commands import cmnds
 
12
from gozerbot.plughelp import plughelp
 
13
from gozerbot.examples import examples
 
14
from gozerbot.tests import tests
 
15
 
 
16
plughelp.add('tail', 'show last <nr> elements of pipeline')
 
17
 
 
18
def handle_tail(bot, ievent):
 
19
 
 
20
    """ used in a pipeline .. show last <nr> elements. """
 
21
 
 
22
    if not ievent.inqueue:
 
23
        ievent.reply("use tail in a pipeline")
 
24
        return
 
25
 
 
26
    try:
 
27
        nr = int(ievent.args[0])
 
28
    except (ValueError, IndexError):
 
29
        ievent.reply('tail <nr>')
 
30
        return
 
31
 
 
32
    result = waitforqueue(ievent.inqueue, 30)
 
33
 
 
34
    if not result:
 
35
        ievent.reply('no data to tail')
 
36
        return
 
37
 
 
38
    ievent.reply(result[-nr:])
 
39
    
 
40
cmnds.add('tail', handle_tail, ['USER', 'CLOUD'], threaded=True)
 
41
examples.add('tail', 'show last <nr> lines of pipeline output', 'list | tail 5')
 
42
tests.add('list | tail 5')