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

« back to all changes in this revision

Viewing changes to gozerplugs/plugs/tail.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

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