3
# (c) Wijnand 'tehmaze' Modderman - http://tehmaze.com
8
__author__ = "Wijnand 'tehmaze' Modderman - http://tehmaze.com"
11
from gozerbot.aliases import aliases
12
from gozerbot.commands import cmnds
13
from gozerbot.periodical import periodical, at
14
from gozerbot.plugins import plugins
15
from gozerbot.examples import examples
16
from gozerbot.plughelp import plughelp
17
from gozerbot.generic import uniqlist
23
plughelp.add('job', 'job management')
26
return len(periodical.jobs)
28
def handle_job(bot, ievent):
29
""" show data of <jobid> """
30
if not ievent.args or not ievent.args[0].isdigit():
31
ievent.reply('<job id>')
33
for job in periodical.jobs:
34
if job.id() == int(ievent.args[0]):
36
if type(next) in [types.FloatType, types.IntType]:
37
next = datetime.datetime(*time.localtime(next)[:7])
38
ievent.reply('%s, fires at %s' % (job.__repr__(), str(next)))
40
ievent.reply('job not found')
42
cmnds.add('job', handle_job, 'USER')
43
examples.add('job', 'show job data of <jobid> ', 'job 1')
45
def handle_joblist(bot, ievent):
48
group = ievent.args[0]
52
for job in periodical.jobs:
53
if group and not job.group == group:
56
result.append('%d (%s)' % (job.id(), job.description))
58
result.append('%d (%s)' % (job.id(), str(job.func.func_name)))
60
ievent.reply('jobs scheduled: ', result, dot=True)
62
ievent.reply('no jobs')
64
cmnds.add('job-list', handle_joblist, 'OPER')
65
examples.add('job-list', 'show all waiting jobs or all jobs belonging to \
66
[group]', '1) job-list 2) job-list rss')
67
aliases.data['jobs'] = 'job-list'
69
def handle_jobgroups(bot, ievent):
70
""" show job groups """
71
result = [job.group for job in periodical.jobs]
73
ievent.reply('job groups: ', uniqlist(result), dot=True)
75
ievent.reply('no jobs')
77
cmnds.add('job-groups', handle_jobgroups, 'OPER')
78
examples.add('job-groups', 'show all job groups', 'job-groups')
80
def handle_jobkill(bot, ievent):
82
if not ievent.args or not ievent.args[0].isdigit():
83
ievent.missing('<job id> [<job id> ...]')
86
ids = [int(jid) for jid in ievent.args]
88
ievent.missing('<job id> [<job id> ...]')
91
periodical.killjob(int(ievent.args[0]))
92
ievent.reply('killed %d jobs' % len(ids))
94
cmnds.add('job-kill', handle_jobkill, 'OPER')
95
examples.add('job-kill', 'kill job with <jobid>', 'job-kill 100000')