-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintcont.py
104 lines (89 loc) · 2.9 KB
/
maintcont.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
The controller bot for maintainer.py
Exactly one instance should be running of it. To check, use /whois maintcont on irc.freenode.net
This script requires the Python IRC library http://python-irclib.sourceforge.net/
Warning: experimental software, use at your own risk
"""
__version__ = '$Id$'
# Author: Balasyum
# http://hu.wikipedia.org/wiki/User:Balasyum
import externals
externals.check_setup('irclib')
from ircbot import SingleServerIRCBot
from irclib import nm_to_n
import threading
import time
import math
tasks = 'rciw|censure'
projtasks = {}
mainters = []
activity = {}
class MaintcontBot(SingleServerIRCBot):
def __init__(self, nickname, server, port=6667):
SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
def on_nicknameinuse(self, c, e):
c.nick(c.get_nickname() + "_")
def on_welcome(self, c, e):
t = threading.Thread(target=self.lister)
t.setDaemon(True)
t.start()
def on_privmsg(self, c, e):
nick = nm_to_n(e.source())
c = self.connection
cmd = e.arguments()[0]
do = cmd.split()
if do[0] == "workerjoin":
c.privmsg(nick, "accepted")
mainters.append([nick, do[1]])
activity[nick] = time.time()
print "worker got, name:", nick, "job:", do[1]
self.retasker(do[1])
elif do[0] == "active":
activity[nick] = time.time()
def on_dccmsg(self, c, e):
pass
def on_dccchat(self, c, e):
pass
def lister(self):
while True:
print
print "worker list:"
for mainter in mainters:
if time.time() - activity[mainter[0]] > 30:
print "*", mainter[0], "has been removed"
mainters.remove(mainter)
del activity[mainter[0]]
self.retasker(mainter[1])
continue
print "mainter name:", mainter[0], "job:", mainter[1]
print "--------------------"
print
time.sleep(1*60)
def retasker(self, group, optask = ''):
ingroup = 0
for mainter in mainters:
if mainter[1] == group:
ingroup += 1
if ingroup == 0:
return
if group in projtasks:
grt = projtasks[group]
else:
grt = tasks
tpc = grt.split('|')
tpcn = round(len(tpc) / ingroup)
i = 0
for mainter in mainters:
if mainter[1] != group:
continue
tts = '|'.join(tpc[int(round(i * tpcn)):int(round((i + 1) * tpcn))])
if tts != False:
self.connection.privmsg(mainter[0], "tasklist " + tts)
i += 1
def main():
bot = MaintcontBot("maintcont", "irc.freenode.net")
bot.start()
if __name__ == "__main__":
main()