cobalt.py

Wed, 05 Nov 2014 00:19:15 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 05 Nov 2014 00:19:15 +0200
changeset 62
052a8a1e3d7d
parent 60
b2db21672012
child 63
a1a864c25e42
permissions
-rwxr-xr-x

- revamped commands, added a much more modular system. not everything migrated yet

0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 '''
25
9fa1df6113c4 - changed the copyright line to use my proper legal name instead of my common calling name
Santeri Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
3 Copyright 2014 Teemu Piippo
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 All rights reserved.
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 Redistribution and use in source and binary forms, with or without
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 modification, are permitted provided that the following conditions
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 are met:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 1. Redistributions of source code must retain the above copyright
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 notice, this list of conditions and the following disclaimer.
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 2. Redistributions in binary form must reproduce the above copyright
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 notice, this list of conditions and the following disclaimer in the
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 documentation and/or other materials provided with the distribution.
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 3. The name of the author may not be used to endorse or promote products
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 derived from this software without specific prior written permission.
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 '''
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 import asyncore
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 import socket
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 import time
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 import sys
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 import traceback
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 import re
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 import json
2
1a24dd2d598e - added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
37 import urllib
1a24dd2d598e - added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
38 import urllib2
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
39 import hgapi
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
40 import os
15
e7999383db5a - don't crash if utf parsing yields an UnicodeDecodeError
Santeri Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
41 import suds
23
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
42 import math
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
43 from datetime import datetime
62
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
44 import commandhandler as CommandHandler
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
45
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
46 CommandHandler.init_data()
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 try:
20
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
49 uid = os.geteuid()
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
50 except:
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
51 uid = -1
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
52
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
53 if uid == 0 and raw_input ('Do you seriously want to run cobalt as root? [y/N] ') != 'y':
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
54 quit()
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
55
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
56 print 'Loading configuration...'
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
57 try:
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 with open ('cobalt.json', 'r') as fp:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 g_config = json.loads (fp.read())
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 except IOError as e:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 print 'couldn\'t open cobalt.json: %s' % e
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 quit()
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 g_admins = g_config['admins']
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 g_mynick = g_config['nickname']
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
67 g_BotActive = False
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
68 g_needCommitsTxtRebuild = True
2
1a24dd2d598e - added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
69
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 #
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 # SOAP stuff
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 #
3
53486417a8e5 - handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
73 suds_active = False
53486417a8e5 - handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
74
53486417a8e5 - handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
75 try:
20
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
76 print 'Initializing MantisBT connection...'
15
e7999383db5a - don't crash if utf parsing yields an UnicodeDecodeError
Santeri Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
77 suds_import = suds.xsd.doctor.Import ('http://schemas.xmlsoap.org/soap/encoding/', 'http://schemas.xmlsoap.org/soap/encoding/')
e7999383db5a - don't crash if utf parsing yields an UnicodeDecodeError
Santeri Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
78 suds_client = suds.client.Client ('https://zandronum.com/tracker/api/soap/mantisconnect.php?wsdl', plugins=[suds.xsd.doctor.ImportDoctor (suds_import)])
3
53486417a8e5 - handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
79 suds_active = True
20
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
80 except Exception as e:
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
81 print 'Failed to establish MantisBT connection: ' + `e`
3
53486417a8e5 - handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
82 pass
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
84 btannounce_active = False
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
85 btannounce_timeout = 0
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
86
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
87 def save_config():
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
88 with open ('cobalt.json', 'w') as fp:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
89 json.dump (g_config, fp, sort_keys = True, indent = 4)
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
90
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
91 def cfg (key, default):
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
92 if not hasattr (g_config, key):
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
93 g_config[key] = default
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
94 save_config()
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
95 return default
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
96 return g_config[key]
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
97
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
98 def bt_updatechecktimeout():
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
99 global btannounce_timeout
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
100 btannounce_timeout = time.time() + (cfg ('btlatest_checkinterval', 5) * 60)
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
101
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
102 if suds_active:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
103 try:
20
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
104 sys.stdout.write ('Retrieving latest tracker ticket... ')
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
105 btannounce_id = suds_client.service.mc_issue_get_biggest_id (g_config['trackeruser'], g_config['trackerpassword'], 0)
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
106 btannounce_active = True
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
107 bt_updatechecktimeout()
20
2603faf5f91b - don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
108 print btannounce_id
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
109 except Exception as e:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
110 pass
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
111
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
112 def bt_getissue(ticket):
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
113 global suds_client
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
114 global g_config
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
115 return suds_client.service.mc_issue_get (g_config['trackeruser'], g_config['trackerpassword'], ticket)
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
116
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
117 def bt_checklatest():
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
118 global btannounce_timeout
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
119 global btannounce_id
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
120
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
121 if time.time() >= btannounce_timeout:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
122 bt_updatechecktimeout()
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
123 newid = btannounce_id
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
124 try:
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
125 newid = suds_client.service.mc_issue_get_biggest_id (g_config['trackeruser'], g_config['trackerpassword'], 0)
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
126 except Exception as e:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
127 pass
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
128
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
129 while newid > btannounce_id:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
130 try:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
131 btannounce_id += 1
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
132 data = bt_getissue (btannounce_id)
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
133
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
134 for client in g_clients:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
135 client.announce_ticket (data)
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
136 except Exception as e:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
137 pass
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
138
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 #
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 # irc_client flags
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 #
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 CLIF_CONNECTED = (1 << 1)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 #
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 # List of all clients
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 #
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 g_clients = []
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 class channel (object):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 name = ""
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 password = ""
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 def __init__ (self, name):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 self.name = name
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 #
19
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
157 # Prints a line to log channel(s)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 #
19
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
159 def chanlog (line):
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 for client in g_clients:
19
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
161 if not client.flags & CLIF_CONNECTED:
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
162 continue
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
163
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
164 for channel in client.channels:
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
165 if channel['logchannel']:
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
166 client.write ("PRIVMSG %s :%s" % (channel['name'], line))
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 #
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 # Exception handling
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 #
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 def handle_exception(excType, excValue, trace):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 excepterm (traceback.format_exception(excType, excValue, trace))
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 def excepterm(data):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 for segment in data:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 for line in segment.splitlines():
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 print line
19
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
178 chanlog (line)
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
179
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 for client in g_clients:
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
181 if len(data) > 0:
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
182 client.exceptdie()
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
183 else:
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
184 client.quit_irc()
19
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
185
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
186 if g_BotActive:
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
187 restart_self()
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
188 else:
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
189 quit()
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 sys.excepthook = handle_exception
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
1
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
193 def check_admin (sender, ident, host, command):
16
6672cecf3ed1 - don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
194 if not "%s@%s" % (ident, host) in g_admins:
1
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
195 raise logical_exception (".%s requires admin access" % command)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196
1
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
197 class logical_exception (Exception):
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
198 def __init__ (self, value):
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
199 self.value = value
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
200 def __str__ (self):
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
201 return self.value
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
202
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
203 # from http://www.daniweb.com/software-development/python/code/260268/restart-your-python-program
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
204 def restart_self():
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
205 python = sys.executable
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
206 os.execl (python, python, * sys.argv)
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
207
59
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
208 def make_commits_txt():
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
209 global g_needCommitsTxtRebuild
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
210
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
211 if g_needCommitsTxtRebuild == False:
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
212 return
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
213
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
214 print 'Building commits.txt...'
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
215 # Update zandronum-everything
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
216 repo = hgapi.Repo ('zandronum-everything')
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
217 repo.hg_command ('pull', '../zandronum-sandbox')
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
218 repo.hg_command ('pull', '../zandronum-sandbox-stable')
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
219
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
220 data = repo.hg_command ('log', '--template', '{node} {date(date, "%y%m%d-%H%M")}\n')
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
221 f = open ('commits.txt', 'w')
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
222 f.write (data)
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
223 f.close()
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
224 g_needCommitsTxtRebuild = False
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
225 #enddef
6a7199a714a1 - make_commits_txt must be higher up..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
226
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
227 ' Check if a repository exists '
48
dbef418cc1c8 - now clones sandbox correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
228 def check_repo_exists (repo_name, repo_owner):
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
229 print 'Checking that %s exists...' % repo_name
48
dbef418cc1c8 - now clones sandbox correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
230 repo_url = 'https://bitbucket.org/%s/%s' % (repo_owner, repo_name)
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
231 zanrepo = hgapi.Repo (repo_name)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
232
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
233 try:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
234 zanrepo.hg_command ('id', '.')
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
235 except hgapi.hgapi.HgException:
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
236 # If the repo does not exist, clone it. zandronum-everything can be spawned off other repos though
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
237 if repo_name == 'zandronum-everything':
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
238 if not os.path.exists (repo_name):
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
239 os.makedirs (repo_name)
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
240
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
241 global g_needCommitsTxtRebuild
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
242 g_needCommitsTxtRebuild = True
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
243 print 'Init %s' % repo_name
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
244 zanrepo.hg_command ('init')
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
245 print 'Cloning zandronum-sandbox into %s' % repo_name
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
246 zanrepo.hg_command ('pull', '../zandronum-sandbox')
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
247 print 'Cloning zandronum-sandbox-stable into %s' % repo_name
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
248 zanrepo.hg_command ('pull', '../zandronum-sandbox-stable')
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
249 print 'Done'
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
250 make_commits_txt()
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
251 return
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
252 #fi
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
253
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
254 try:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
255 print 'Cloning %s...' % repo_name
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
256 zanrepo.hg_clone (repo_url, repo_name)
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
257 print 'Cloning done.'
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
258 except Exception as e:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
259 print 'Unable to clone %s from %s: %s' % (repo_name, repo_url, str (`e`))
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
260 quit(1)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
261 #tried
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
262 #enddef
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
263
48
dbef418cc1c8 - now clones sandbox correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
264 check_repo_exists ('zandronum', 'Torr_Samaho')
dbef418cc1c8 - now clones sandbox correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
265 check_repo_exists ('zandronum-stable', 'Torr_Samaho')
dbef418cc1c8 - now clones sandbox correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
266 check_repo_exists ('zandronum-sandbox', 'crimsondusk')
51
b0209b707fa2 - now also tracks sandbox-stable
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
267 check_repo_exists ('zandronum-sandbox-stable', 'crimsondusk')
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
268 check_repo_exists ('zandronum-everything', '')
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
269
51
b0209b707fa2 - now also tracks sandbox-stable
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
270 repocheck_timeout = {'zandronum':(time.time()) + 15, 'zandronum-stable':(time.time() + 15), 'zandronum-sandbox':(time.time()) + 15, 'zandronum-sandbox-stable':(time.time()) + 15}
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
271
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
272 def get_commit_data (zanrepo, rev, template):
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
273 return zanrepo.hg_command ('log', '-l', '1', '-r', rev, '--template', template)
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
274 #enddef
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
275
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
276 def decipher_hgapi_error (e):
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
277 # Blah, hgapi, why must your error messages be so mangled?
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
278 try:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
279 rawmsg = e.message.replace('\n', '').replace('" +','').replace('\t','')
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
280 errmsg = re.compile (r'.*: tErr: (.*)Out:.*').match (rawmsg).group (1)
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
281 return [True, errmsg]
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
282 except:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
283 return [False, '']
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
284 #endtry
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
285 #enddef
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
286
46
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
287 def bbcodify(commit_diffstat):
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
288 result=''
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
289 for line in commit_diffstat.split('\n'):
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
290 # Add green color-tags for the ++++++++++ stream
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
291 rex = re.compile (r'^(.*)\|(.*) (\+*)(-*)(.*)$')
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
292 match = rex.match (line)
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
293 if match:
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
294 line = '%s|%s [color=#5F7]%s[/color][color=#F53]%s[/color]%s\n' \
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
295 % (match.group (1), match.group (2), match.group (3), match.group (4), match.group (5))
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
296
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
297 # Tracker doesn't seem to like empty color tags
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
298 line = line.replace ('[color=#5F7][/color]', '').replace ('[color=#F53][/color]', '')
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
299 #else:
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
300 #rex = re.compile (r'^(.*) ([0-9]+) insertions\(\+\), ([0-9]+) deletions\(\-\)$')
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
301 #match = rex.match (line)
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
302 #if match:
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
303 #line = '%s [b][color=green]%s[/color][/b] insertions, [b][color=red]%s[/color][/b] deletions\n' \
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
304 #% (match.group (1), match.group (2), match.group (3))
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
305
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
306 result += line
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
307 #done
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
308
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
309 return result
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
310 #enddef
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
311
50
d9ec5928759e - goddamnit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
312 def find_developer_by_email (commit_email):
49
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
313 for developer, emails in g_config['developer_emails'].iteritems():
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
314 for email in emails:
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
315 if commit_email == email:
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
316 return developer
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
317 #fi
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
318 #done
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
319 #done
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
320
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
321 return ''
49
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
322 #enddef
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
323
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
324 ' Retrieves and processes commits for zandronum repositories '
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
325 ' Ensure both repositories are OK before using this! '
34
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
326 def process_zan_repo_updates (repo_name):
62
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
327 return
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
328
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
329 global repocheck_timeout
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
330 global suds_client
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
331 global g_config
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
332 global g_clients
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
333
34
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
334 usestable = repo_name == 'zandronum-stable'
51
b0209b707fa2 - now also tracks sandbox-stable
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
335 usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable'
47
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
336 repo_owner = 'Torr_Samaho' if not usesandbox else 'crimsondusk'
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
337 repo_url = 'https://bitbucket.org/%s/%s' % (repo_owner, repo_name)
34
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
338 num_commits = 0
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
339
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
340 if time.time() < repocheck_timeout[repo_name]:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
341 return
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
342
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
343 repocheck_timeout[repo_name] = time.time() + (cfg ('hg_checkinterval', 15) * 60)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
344 zanrepo = hgapi.Repo (repo_name)
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
345 commit_data = []
42
adbf42ede463 - use a specific delimeter string '@@@@@@@@@@@' for hg incoming data as some commit messages are multi-line
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
346 delimeter = '@@@@@@@@@@'
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
347
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
348 try:
42
adbf42ede463 - use a specific delimeter string '@@@@@@@@@@@' for hg incoming data as some commit messages are multi-line
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
349 data = zanrepo.hg_command ('incoming', '--quiet', '--template',
adbf42ede463 - use a specific delimeter string '@@@@@@@@@@@' for hg incoming data as some commit messages are multi-line
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
350 '{node|short} {desc}' + delimeter)
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
351 except hgapi.hgapi.HgException as e:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
352 deciphered = decipher_hgapi_error (e)
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
353
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
354 if deciphered[0] and len(deciphered[1]) > 0:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
355 chanlog ("error while using hg import on %s: %s" % (repo_name, deciphered[1]))
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
356 #fi
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
357
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
358 return
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
359 except Exception as e:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
360 chanlog ("%s" % `e`)
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
361 return
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
362 #tried
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
363
42
adbf42ede463 - use a specific delimeter string '@@@@@@@@@@@' for hg incoming data as some commit messages are multi-line
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
364 for line in data.split (delimeter):
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
365 if line == '':
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
366 continue
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
367 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
368
43
637cee1d89f0 - removed line delimeters from hg incoming regex parser
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
369 rex = re.compile (r'([^ ]+) (.+)')
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
370 match = rex.match (line)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
371 failed = False
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
372
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
373 if not match:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
374 chanlog ('malformed hg data: %s' % line)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
375 continue
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
376 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
377
32
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
378 commit_node = match.group (1)
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
379 commit_message = match.group (2)
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
380 commit_data.append ([commit_node, commit_message])
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
381 #done
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
382
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
383 if len (commit_data) > 0:
53
e2b958a7e083 - damnit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
384 pull_args = [];
e2b958a7e083 - damnit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
385
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
386 for commit in commit_data:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
387 pull_args.append ('-r');
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
388 pull_args.append (commit[0]);
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
389 #done
32
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
390
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
391 try:
52
24ca8de770ac - fixed pull logic
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
392 zanrepo.hg_command ('pull', *pull_args)
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
393
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
394 # Also pull these commits to the zandronum main repository
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
395 if usestable:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
396 devrepo = hgapi.Repo ('zandronum')
52
24ca8de770ac - fixed pull logic
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
397 devrepo.hg_command ('pull', '../zandronum-stable', *pull_args)
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
398 #fi
47
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
399
51
b0209b707fa2 - now also tracks sandbox-stable
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
400 # Pull everything into sandboxes too
47
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
401 if not usesandbox:
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
402 devrepo = hgapi.Repo ('zandronum-sandbox')
52
24ca8de770ac - fixed pull logic
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
403 devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args)
51
b0209b707fa2 - now also tracks sandbox-stable
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
404
b0209b707fa2 - now also tracks sandbox-stable
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
405 devrepo = hgapi.Repo ('zandronum-sandbox-stable')
52
24ca8de770ac - fixed pull logic
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
406 devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args)
47
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
407 #fi
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
408
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
409 devrepo = hgapi.Repo ('zandronum-everything')
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
410 devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args)
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
411
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
412 global g_needCommitsTxtRebuild
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
413 g_needCommitsTxtRebuild = True
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
414 except Exception as e:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
415 chanlog ('Warning: unable to pull: %s' % `e`)
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
416 return
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
417 #tried
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
418 #fi
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
419
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
420 for commit in commit_data:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
421 commit_node = commit[0]
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
422 commit_message = commit[1]
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
423
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
424 try:
47
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
425 if usesandbox:
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
426 commit_author = get_commit_data (zanrepo, commit_node, '{author}')
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
427 commit_url = '%s/commits/%s' % (repo_url, commit_node)
49
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
428 commit_email = ''
47
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
429
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
430 # Remove the email address from the author if possible
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
431 rex = re.compile (r'^(.+) <([^>]+)>$.*')
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
432 match = rex.match (commit_author)
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
433 if match:
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
434 commit_author = match.group (1)
49
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
435 commit_email = match.group (2)
47
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
436 #fi
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
437
49
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
438 commit_trackeruser = find_developer_by_email (commit_email)
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
439 committer = commit_trackeruser if commit_trackeruser != '' else commit_author
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
440
47
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
441 for irc_client in g_clients:
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
442 for channel in irc_client.cfg['channels']:
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
443 if 'btprivate' in channel and channel['btprivate'] == True:
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
444 irc_client.privmsg (channel['name'],
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
445 "%s: new commit %s by %s: %s"
49
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
446 % (repo_name, commit_node, committer, commit_url))
47
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
447
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
448 for line in commit_message.split ('\n'):
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
449 irc_client.privmsg (channel['name'], line)
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
450 #fi
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
451 #done
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
452 #done
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
453
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
454 num_commits += 1
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
455 continue
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
456 #fi
103f184951bb - added sandbox support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
457
54
180ae24d46f2 - also check for 'should fix' in commit messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 53
diff changeset
458 rex = re.compile (r'^.*(fixes|resolves|addresses|should fix) ([0-9]+).*$')
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
459 match = rex.match (commit_message)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
460
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
461 if not match:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
462 continue # no "fixes" message in the commit
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
463 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
464
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
465 ticket_id = int (match.group (2))
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
466
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
467 # Acquire additional data
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
468 moredata = get_commit_data (zanrepo, commit_node,
46
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
469 '{author|nonempty}\n{date(date, \'%A %d %B %Y %T\')}').split('\n')
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
470
46
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
471 if len (moredata) != 2:
40
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
472 chanlog ('error while processing %s: malformed hg data' % commit_node)
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
473 continue
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
474 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
475
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
476 commit_author = moredata[0]
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
477 commit_date = moredata[1]
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
478 commit_email = ""
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
479
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
480 try:
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
481 ticket_data = suds_client.service.mc_issue_get (g_config['trackeruser'],
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
482 g_config['trackerpassword'], ticket_id)
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
483 except Exception as e:
40
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
484 chanlog ('error while processing %s: %s' % (commit_node, `e`))
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
485 continue
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
486 #tried
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
487
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
488 # Remove the email address from the author if possible
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
489 rex = re.compile (r'^(.+) <([^>]+)>$.*')
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
490 match = rex.match (commit_author)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
491 if match:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
492 commit_author = match.group (1)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
493 commit_email = match.group (2)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
494 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
495
46
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
496 commit_diffstat = zanrepo.hg_command ('diff', '--change', commit_node, '--stat')
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
497
46
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
498 if len(commit_diffstat) > 0:
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
499 # commit_diffstat = 'Changes in files:\n[code]\n' + commit_diffstat + '\n[/code]'
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
500 commit_diffstat = 'Changes in files:\n' + bbcodify(commit_diffstat)
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
501 else:
c4d231fdf1c0 - now with a more detailed diffstat, in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
502 commit_diffstat = 'No changes in files.'
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
503
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
504 # Compare the email addresses against known developer usernames
49
2df3d5b2f364 - print username when possible
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
505 commit_trackeruser = find_developer_by_email (commit_email)
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
506
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
507 if commit_trackeruser != '':
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
508 commit_author += ' [%s]' % commit_trackeruser
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
509 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
510
37
3399d716b3ae - fixed: the [url] tags in BT messages had unnecessary quotes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
511 message = 'Issue addressed by commit %s: [b][url=%s/commits/%s]%s[/url][/b]' \
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
512 % (commit_node, repo_url, commit_node, commit_message)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
513 message += "\nCommitted by %s on %s\n\n%s" \
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
514 % (commit_author, commit_date, commit_diffstat)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
515
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
516 need_update = False
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
517
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
518 # If not already set, set handler
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
519 if not 'handler' in ticket_data:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
520 ticket_data['handler'] = {'name': commit_trackeruser}
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
521 need_update = True
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
522 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
523
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
524 # Find out the status level of the ticket
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
525 needs_testing_level = 70
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
526
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
527 if ticket_data['status']['id'] < needs_testing_level:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
528 ticket_data.status['id'] = needs_testing_level
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
529 need_update = True
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
530 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
531
35
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
532 # Set target version if not set
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
533 if not 'target_version' in ticket_data:
45
fdfcdf405b16 - bump interpreted version number of zandronum-stable from 1.3 to 1.4
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
534 ticket_data['target_version'] = '1.4' if repo_name == 'zandronum-stable' else '2.0'
35
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
535 need_update = True
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
536 elif (ticket_data['target_version'] == '2.0' or ticket_data['target_version'] == '2.0-beta') \
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
537 and repo_name == 'zandronum-stable':
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
538 # Target version was 2.0 but this was just committed to zandronum-stable, adjust
45
fdfcdf405b16 - bump interpreted version number of zandronum-stable from 1.3 to 1.4
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
539 ticket_data['target_version'] = '1.4'
35
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
540 need_update = True
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
541 elif ticket_data['target_version'] == '2.0-beta':
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
542 # Fix target version from 2.0-beta to 2.0
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
543 ticket_data['target_version'] = '2.0'
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
544 need_update = True
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
545 #fi
237e82bcd02f - update target version in tickets when acting upon commit data
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
546
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
547 # Announce on IRC
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
548 for irc_client in g_clients:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
549 for channel in irc_client.cfg['channels']:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
550 if 'btannounce' in channel and channel['btannounce'] == True:
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
551 irc_client.privmsg (channel['name'],
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
552 "%s: commit %s fixes issue %d: %s"
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
553 % (repo_name, commit_node, ticket_id, commit_message))
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
554 irc_client.privmsg (channel['name'],
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
555 "Read all about it here: " + irc_client.get_ticket_url (ticket_id))
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
556 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
557 #done
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
558 #done
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
559
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
560 if need_update:
36
543d7a5e3b8b - when updating BT tickets, the note data must be cleared in order to not update all the tickets in the ticket. WTF is MantisBT smoking?
Teemu Piippo <crimsondusk64@gmail.com>
parents: 35
diff changeset
561 # We need to remove the note data, otherwise the ticket notes
543d7a5e3b8b - when updating BT tickets, the note data must be cleared in order to not update all the tickets in the ticket. WTF is MantisBT smoking?
Teemu Piippo <crimsondusk64@gmail.com>
parents: 35
diff changeset
562 # will get unnecessary updates. WTF, MantisBT?
543d7a5e3b8b - when updating BT tickets, the note data must be cleared in order to not update all the tickets in the ticket. WTF is MantisBT smoking?
Teemu Piippo <crimsondusk64@gmail.com>
parents: 35
diff changeset
563 ticket_data.notes = []
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
564 suds_client.service.mc_issue_update (g_config['trackeruser'], g_config['trackerpassword'], ticket_id, ticket_data)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
565 #fi
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
566
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
567 suds_client.service.mc_issue_note_add (g_config['trackeruser'], g_config['trackerpassword'], ticket_id, { 'text': message })
34
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
568 num_commits += 1
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
569 except Exception as e:
32
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
570 chanlog ('Error while processing %s: %s' % (commit_node, `e`))
39
afd590258a93 - reworked repository watching. Now uses incoming only once to get a list of commits, then pulls, then operates on pulled data. The incoming command doesn't seem to support the '-r' switch properly? Should also be a bit faster now and should use less networking.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 38
diff changeset
571 continue
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
572 #tried
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
573 #done
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
574
34
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
575 return num_commits > 0
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
576 #enddef
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
577
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
578 def plural (a):
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
579 return '' if a == 1 else 's'
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
580
1
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
581 #
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
582 # Main IRC client class
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
583 #
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
584 class irc_client (asyncore.dispatcher):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585 def __init__ (self, cfg, flags):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586 self.name = cfg['name']
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
587 self.host = cfg['address']
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
588 self.port = cfg['port']
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 self.password = cfg['password'] if 'password' in cfg else ''
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590 self.channels = cfg['channels']
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
591 self.flags = flags
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592 self.send_buffer = list()
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
593 self.umode = cfg['umode'] if 'umode' in cfg else ''
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
594 self.cfg = cfg
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
595 self.mynick = ''
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
596 self.verbose = g_config['verbose'] if 'verbose' in g_config else False
11
90851b22ab88 - gddmnt, python. you and your type system
Santeri Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
597 self.commandprefix = g_config['commandprefix'][0] if 'commandprefix' in g_config else '.'
8
dd467db4b18e - made conflictsuffix configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 7
diff changeset
598
19
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
599 for channel in self.channels:
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
600 if not 'logchannel' in channel:
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
601 channel['logchannel'] = False
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
602 channel['namesdone'] = True
27
ac59b5ae7a78 - disabled unstable/incomplete linkbot code.. I need to learn to stash changes proper
Teemu Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
603 #channel['haslinkbot'] = False
19
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
604
8
dd467db4b18e - made conflictsuffix configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 7
diff changeset
605 if not 'conflictsuffix' in self.cfg:
dd467db4b18e - made conflictsuffix configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 7
diff changeset
606 self.cfg['conflictsuffix'] = '`'
dd467db4b18e - made conflictsuffix configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 7
diff changeset
607
7
438dc247ceb9 - handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
608 self.desired_name = self.cfg['nickname'] if 'nickname' in self.cfg else g_config['nickname']
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
609 g_clients.append (self)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
610 asyncore.dispatcher.__init__ (self)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
611 self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
612 self.connect ((self.host, self.port))
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
613
7
438dc247ceb9 - handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
614 def register_to_irc (self):
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
615 ident = self.cfg['ident'] if 'ident' in self.cfg else g_config['ident']
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
616 gecos = self.cfg['gecos'] if 'gecos' in self.cfg else g_config['gecos']
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
617 if 'password' in self.cfg:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
618 self.write ("PASS %s" % self.cfg['password'])
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
619 self.write ("USER %s * * :%s" % (ident, gecos))
7
438dc247ceb9 - handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
620 self.write ("NICK %s" % self.mynick)
438dc247ceb9 - handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
621
438dc247ceb9 - handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
622 def handle_connect (self):
438dc247ceb9 - handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
623 self.mynick = self.desired_name
438dc247ceb9 - handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
624 print "Connected to [%s] %s:%d" % (self.name, self.host, self.port)
438dc247ceb9 - handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
625 self.register_to_irc()
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
626
17
f604687dd35b - don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
627 def write (self, utfdata):
f604687dd35b - don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
628 try:
f604687dd35b - don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
629 self.send_buffer.append ("%s" % utfdata.decode("utf-8","ignore").encode("ascii","ignore"))
f604687dd35b - don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
630 except UnicodeEncodeError:
f604687dd35b - don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
631 pass
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
632
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
633 def handle_close (self):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
634 print "Connection to [%s] %s:%d terminated." % (self.name, self.host, self.port)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635 self.close()
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
636
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
637 def handle_write (self):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
638 self.send_all_now()
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
639
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
640 def readable (self):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
641 return True
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
642
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
643 def writable (self):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644 return len (self.send_buffer) > 0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
646 def send_all_now (self):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
647 for line in self.send_buffer:
9
0604f6b9f781 - added verbosity setting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
648 if self.verbose:
0604f6b9f781 - added verbosity setting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
649 print "[%s] <- %s" % (self.name, line)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650 self.send ("%s\n" % line)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
651 self.send_buffer = []
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
653 def handle_read (self):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
654 lines = self.recv (4096).splitlines()
2
1a24dd2d598e - added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
655 for utfline in lines:
16
6672cecf3ed1 - don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
656 try:
17
f604687dd35b - don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
657 line = utfline.decode("utf-8","ignore").encode("ascii","ignore")
16
6672cecf3ed1 - don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
658 except UnicodeDecodeError:
6672cecf3ed1 - don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
659 continue
6672cecf3ed1 - don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
660
9
0604f6b9f781 - added verbosity setting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
661 if self.verbose:
0604f6b9f781 - added verbosity setting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
662 print "[%s] -> %s" % (self.name, line)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
663
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
664 if line.startswith ("PING :"):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
665 self.write ("PONG :%s" % line[6:])
14
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
666 else:
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
667 words = line.split(" ")
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
668 if len(words) >= 2:
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
669 if words[1] == "001":
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
670 self.flags |= CLIF_CONNECTED
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
671
14
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
672 for channel in self.cfg['channels']:
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
673 self.write ("JOIN %s %s" % (channel['name'], channel['password'] if 'password' in channel else ''))
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
674
14
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
675 if 'umode' in self.cfg:
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
676 self.write ('MODE %s %s' % (self.mynick, self.cfg['umode']))
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
677 elif words[1] == "PRIVMSG":
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
678 self.handle_privmsg (line)
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
679 elif words[1] == 'JOIN':
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
680 rex = re.compile (r'^:([^!]+)!([^@]+)@([^ ]+) JOIN :#(.+)')
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
681 match = rex.match (line)
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
682
27
ac59b5ae7a78 - disabled unstable/incomplete linkbot code.. I need to learn to stash changes proper
Teemu Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
683 #if match and match.group(1).toLower() == 'linkbot':
ac59b5ae7a78 - disabled unstable/incomplete linkbot code.. I need to learn to stash changes proper
Teemu Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
684 #channel_by_name (match.group(4))['haslinkbot'] = True
14
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
685 elif words[1] == 'QUIT':
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
686 rex = re.compile (r'^:([^!]+)!([^@]+)@([^ ]+) QUIT')
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
687 match = rex.match (line)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
688
14
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
689 # Try reclaim our nickname if possible
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
690 if match and match.group(1) == self.desired_name:
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
691 self.mynick = self.desired_name
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
692 self.write ("NICK %s" % self.mynick)
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
693
27
ac59b5ae7a78 - disabled unstable/incomplete linkbot code.. I need to learn to stash changes proper
Teemu Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
694 #if match and match.group(1).toLower() == 'linkbot':
ac59b5ae7a78 - disabled unstable/incomplete linkbot code.. I need to learn to stash changes proper
Teemu Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
695 #for channel in self.channels:
ac59b5ae7a78 - disabled unstable/incomplete linkbot code.. I need to learn to stash changes proper
Teemu Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
696 #channels['haslinkbot'] = False
14
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
697 elif words[1] == "433":
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
698 #:irc.localhost 433 * cobalt :Nickname is already in use.
558379fd6d6a - heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
699 self.mynick = '%s%s' % (self.mynick, self.cfg['conflictsuffix'])
7
438dc247ceb9 - handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
700 self.write ("NICK %s" % self.mynick)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
701
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
702 # Check for new issues on the bugtracker
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
703 bt_checklatest()
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
704
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
705 # Check for new commits in the repositories
51
b0209b707fa2 - now also tracks sandbox-stable
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
706 for n in ['zandronum-stable', 'zandronum', 'zandronum-sandbox', 'zandronum-sandbox-stable']:
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
707 process_zan_repo_updates (n)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
708
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
709 def channel_by_name (self, name):
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
710 for channel in self.channels:
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
711 if channel['name'].upper() == args[0].upper():
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
712 return channel
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
713 else:
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
714 raise logical_exception ('unknown channel ' + args[0])
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
715
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
716 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
717 #
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
718 # Handle a PRIVMSG line from the IRC server
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
719 #
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
720 def handle_privmsg (self, line):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
721 rex = re.compile (r'^:([^!]+)!([^@]+)@([^ ]+) PRIVMSG ([^ ]+) :(.+)$')
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
722 match = rex.match (line)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
723 if match:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
724 sender = match.group (1)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
725 user = match.group (2)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
726 host = match.group (3)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
727 channel = match.group (4)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
728 message = match.group (5)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
729 replyto = channel if channel != g_mynick else sender
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
730
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
731 # Check for tracker url in the message
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 http_regex = re.compile (r'.*http(s?)://%s/view\.php\?id=([0-9]+).*' % g_config['trackerurl'])
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
733 http_match = http_regex.match (line)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
734
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
735 # Check for command.
10
1b726db7b0ec - respect the commandprefix option
Santeri Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
736 if len(message) >= 2 and message[0] == self.commandprefix and message[1] != self.commandprefix:
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
737 stuff = message[1:].split(' ')
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
738 command = stuff[0]
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
739 args = stuff[1:]
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
740 try:
62
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
741 self.handle_command (sender, user, host, replyto, command, args, message)
21
8c389f46a056 - handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
742 except logical_exception as e:
8c389f46a056 - handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
743 for line in e.value.split ('\n'):
8c389f46a056 - handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
744 if len(line) > 0:
8c389f46a056 - handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
745 self.privmsg (replyto, "error: %s" % line)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
746 elif http_match:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
747 self.get_ticket_data (replyto, http_match.group (2), False)
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
748 else:
19
ca618214fd07 - control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
749 chanlog ("Recieved bad PRIVMSG: %s" % line)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
750
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
751 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
752 #
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
753 # Get the URL for a specified ticket
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
754 #
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
755 def get_ticket_url (self, ticket):
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
756 return 'https://%s/view.php?id=%s' % (g_config['trackerurl'], ticket)
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
757
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
758 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
759 #
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
760 # Retrieve a ticket from mantisbt
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
761 #
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
762 def get_ticket_data (self, replyto, ticket, withlink):
3
53486417a8e5 - handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
763 if suds_active == False:
53486417a8e5 - handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
764 return
53486417a8e5 - handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
765
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
766 data = {}
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
767 try:
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
768 data = bt_getissue (ticket)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
769 except Exception, e:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
770 self.privmsg (replyto, "Failed to get info for issue %s: %s" % (ticket, `e`))
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
771
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
772 if data:
32
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
773 if data['view_state']['name'] == 'private':
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
774 allowprivate = False
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
775
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
776 for channel in self.channels:
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
777 if channel['name'] == replyto and 'btprivate' in channel and channel['btprivate'] == True:
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
778 allowprivate = True
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
779 break
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
780 #fi
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
781 #done
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
782
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
783 if not allowprivate:
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
784 self.privmsg (replyto, 'Error: ticket %s is private' % ticket)
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
785 return
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
786 #fi
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
787 #fi
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
788
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
789 self.privmsg (replyto, "Issue %s: %s: Reporter: %s, assigned to: %s, status: %s (%s)" % \
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
790 (ticket, \
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
791 data.summary, \
4
bd9508f8a10f - don't crash if ticket data doesn't have a reporter name (can happen if the reporter is banned)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 3
diff changeset
792 data.reporter.name if hasattr (data.reporter, 'name') else "<unknown>", \
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
793 data.handler.name if hasattr (data, 'handler') else "nobody", \
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
794 data.status.name, \
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
795 data.resolution.name))
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
796
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
797 if withlink:
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
798 self.privmsg (replyto, "Read all about it here: " + self.get_ticket_url (ticket))
32
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
799 #fi
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
800 #fi
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
801 #enddef
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
802
62
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
803 def save_config (self):
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
804 save_config()
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
805
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
806 def is_admin (self, ident, host):
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
807 return ("%s@%s" % (ident, host)) in g_admins
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
808
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
809 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
810 #
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
811 # Process an IRC command
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
812 #
62
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
813 def handle_command (self, sender, ident, host, replyto, command, args, message):
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
814 kvargs = {'sender': sender, 'ident': ident, 'host': host, 'replyto': replyto, 'cmdname': command, 'message': message}
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
815
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
816 try:
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
817 result = CommandHandler.call_command (self, **kvargs)
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
818
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
819 if result:
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
820 return
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
821 else:
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
822 print 'CommandHandler.call_command returned false'
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
823 except CommandHandler.CommandError as e:
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
824 lines = str (e).split ('\n')
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
825 self.privmsg (replyto, 'error: %s' % lines[0])
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
826
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
827 for line in lines[1:]:
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
828 self.privmsg (replyto, ' ' + line)
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
829 return
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
830 #tried
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
831
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
832 if command == 'ticket':
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
833 if len(args) != 1:
1
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
834 raise logical_exception ("usage: .%s <ticket>" % command)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
835 self.get_ticket_data (replyto, args[0], True)
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
836 elif command == 'testannounce':
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
837 check_admin (sender, ident, host, command)
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
838 if len(args) != 1:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
839 raise logical_exception ("usage: .%s <ticket>" % command)
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
840 self.announce_ticket (bt_getissue (args[0]))
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
841 elif command == 'checkhg':
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
842 check_admin (sender, ident, host, command)
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
843 global repocheck_timeout
51
b0209b707fa2 - now also tracks sandbox-stable
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
844 repocheck_timeout = {'zandronum':0, 'zandronum-stable':0, 'zandronum-sandbox':0, 'zandronum-sandbox-stable':0}
34
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
845
51
b0209b707fa2 - now also tracks sandbox-stable
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
846 for n in ['zandronum-stable', 'zandronum', 'zandronum-sandbox', 'zandronum-sandbox-stable']:
34
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
847 numcommits = process_zan_repo_updates (n)
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
848
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
849 if numcommits == 0:
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
850 self.privmsg (replyto, 'No new commits in ' + n)
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
851 #fi
1a1ee9e8bda6 - be more verbose when .checkhg is used
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
852 #done
6
2c6265a99d32 - added .die
Santeri Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
853 elif command == 'die':
2c6265a99d32 - added .die
Santeri Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
854 check_admin (sender, ident, host, command)
2c6265a99d32 - added .die
Santeri Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
855 quit()
23
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
856 elif command == 'convert':
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
857 if len(args) != 3 or args[1] != 'as':
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
858 raise logical_exception ("usage: .%s <value> as <valuetype>" % command)
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
859
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
860 value = float (args[0])
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
861 valuetype = args[2]
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
862
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
863 if valuetype in ['radians', 'degrees']:
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
864 if valuetype == 'radians':
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
865 radvalue = value
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
866 degvalue = (value * 180.) / math.pi
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
867 else:
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
868 radvalue = (value * math.pi) / 180.
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
869 degvalue = value
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
870
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
871 self.privmsg (replyto, '%s radians, %s degrees (%s)' %(radvalue, degvalue, degvalue % 360.))
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
872 elif valuetype in ['celsius', 'fahrenheit']:
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
873 if valuetype == 'celsius':
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
874 celvalue = value
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
875 fahrvalue = value * 1.8 + 32
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
876 else:
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
877 celvalue = (value - 32) / 1.8
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
878 fahrvalue = value
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
879
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
880 self.privmsg (replyto, '%s degrees celsius, %s degrees fahrenheit' %(celvalue, fahrvalue))
c25944cac3e6 - added .convert with angle and temperature conversions
Santeri Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
881 else:
24
3ef436e7d7c1 - updated error
Santeri Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
882 raise logical_exception ('unknown valuetype, expected one of: degrees, radians (angle conversion), ' +
3ef436e7d7c1 - updated error
Santeri Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
883 'celsius, fahrenheit (temperature conversion)')
28
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
884 elif command == 'urban' or command == 'ud':
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
885 try:
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
886 if len(args) < 1:
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
887 raise logical_exception ('usage: %s <word>' % command)
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
888
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
889 url = 'http://api.urbandictionary.com/v0/define?term=%s' % ('%20'.join (args))
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
890 response = urllib2.urlopen (url).read()
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
891 data = json.loads (response)
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
892
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
893 if 'list' in data and len(data['list']) > 0 and 'word' in data['list'][0] and 'definition' in data['list'][0]:
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
894 word = data['list'][0]['word']
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
895 definition = data['list'][0]['definition'].replace ('\r', ' ').replace ('\n', ' ').replace (' ', ' ')
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
896 up = data['list'][0]['thumbs_up']
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
897 down = data['list'][0]['thumbs_down']
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
898 self.privmsg (replyto, "\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down))
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
899 else:
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
900 self.privmsg (replyto, "couldn't find a definition of \002%s\002" % args[0])
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
901 except logical_exception as e:
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
902 raise e
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
903 except Exception as e:
30257c78904f - added urban dictionary lookup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
904 raise logical_exception ('Urban dictionary lookup failed: %s' % `e`)
40
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
905 elif command == 'hg':
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
906 check_admin (sender, ident, host, command)
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
907
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
908 if len(args) < 2:
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
909 raise logical_exception ('usage: %s <repo> <command...>' % command)
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
910
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
911 try:
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
912 repo = hgapi.Repo (args[0])
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
913 result = repo.hg_command (*args[1:])
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
914 self.privmsg (replyto, result)
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
915 except hgapi.hgapi.HgException as e:
41
aa214b9504de - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
916 result = decipher_hgapi_error (e)
aa214b9504de - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
917
aa214b9504de - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
918 if result[0]:
aa214b9504de - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
919 self.privmsg (replyto, 'error: %s' % result[1])
aa214b9504de - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
920 else:
44
616743868d4a - post the raw-form error if unable to decipher
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
921 self.privmsg (replyto, 'error: %s' % `e`)
41
aa214b9504de - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
922 #fi
40
f6512aacb114 - fine tuning, added .hg command
Teemu Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
923 #tried
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
924 elif command == 'changeset' or command == 'cset' or command == 'rev':
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
925 if len(args) != 1:
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
926 raise logical_exception ('usage: %s <changeset>' % command)
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
927
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
928 repo = hgapi.Repo ('zandronum-everything')
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
929 data = ""
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
930 node = args[0]
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
931
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
932 # Possibly we're passed a date version instead. Try find the node for this.
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
933 try:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
934 datetime.strptime (args[0], '%y%m%d-%H%M')
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
935 make_commits_txt()
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
936 commits_txt = open ('commits.txt', 'r')
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
937
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
938 for line in commits_txt:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
939 data = line.replace ('\n', '').split (' ')
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
940 if data[1] == args[0]:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
941 node = data[0]
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
942 break
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
943 else:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
944 self.privmsg (replyto, 'couldn\'t find changset for date %s' % args[0])
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
945 return
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
946 #done
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
947 except ValueError:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
948 pass
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
949 #tried
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
950
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
951 # The sandboxes contain all revisions in zandronum and zandronum-stable.
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
952 # Thus we only need to try find the revision in the sandbox repos.
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
953 try:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
954 repo.hg_command ("log", "-r", node, "--template", " ")
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
955 except hgapi.hgapi.HgException:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
956 self.privmsg (replyto, 'couldn\'t find changeset %s' % (node))
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
957 return
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
958 #tried
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
959
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
960 try:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
961 data = repo.hg_command ("log", "-r", node, "--template",
60
b2db21672012 - try print dateversion more correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
962 "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date(date, '%y%m%d-%H%M')}@@@@@@@{date(date, '%s')}")
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
963 data = data.split ('@@@@@@@')
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
964
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
965 node = data[0]
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
966 message = data[1]
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
967 author = data[2]
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
968 diffstat = data[3]
60
b2db21672012 - try print dateversion more correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
969 dateversion = data[4]
b2db21672012 - try print dateversion more correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
970 date = datetime.fromtimestamp (int (data[5]))
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
971 delta = datetime.now() - date
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
972 datestring = ''
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
973
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
974 # Remove the email address from the author if possible
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
975 match = re.compile (r'^(.+) <([^>]+)>$.*').match (author)
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
976 if match:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
977 author = match.group (1)
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
978 email = match.group (2)
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
979
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
980 username = find_developer_by_email (email)
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
981
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
982 if username != '':
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
983 author = username
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
984
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
985 if delta.days < 4:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
986 if delta.days == 0:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
987 if delta.seconds < 60:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
988 datestring = 'just now'
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
989 elif delta.seconds < 3600:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
990 minutes = delta.seconds / 60
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
991 datestring = '%d minute%s ago' % (minutes, plural (minutes))
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
992 else:
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
993 hours = delta.seconds / 3600
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
994 datestring = '%d hour%s ago' % (hours, plural (hours))
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
995 else:
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
996 datestring = '%d day%s ago' % (delta.days, plural (delta.days))
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
997 else:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
998 datestring = 'on %s' % (str (date))
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
999 #fi
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
1000
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1001 self.privmsg (replyto, 'changeset %s (%s): committed by %s %s (%s)' % \
60
b2db21672012 - try print dateversion more correctly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
1002 (node, dateversion, author, datestring, diffstat))
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
1003
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1004 for line in message.split ('\n'):
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1005 self.privmsg (replyto, ' ' + line)
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1006 except hgapi.hgapi.HgException as e:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1007 result = decipher_hgapi_error (e)
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
1008
58
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1009 if result[0]:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1010 self.privmsg (replyto, 'error: %s' % result[1])
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1011 else:
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1012 self.privmsg (replyto, 'error: %s' % `e`)
577cecfea94e - now able to get changeset by date
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
1013 #tried
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
1014 # else:
55
441a04262cb4 - added the .changeset (aka .cset or .rev) command to get revision info
Teemu Piippo <crimsondusk64@gmail.com>
parents: 54
diff changeset
1015 # raise logical_exception ("unknown command `.%s`" % command)
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1016
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1017 #
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1018 # Print a ticket announce to appropriate channels
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1019 #
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1020 def announce_ticket (self, data):
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1021 idstring = "%d" % data.id
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1022 while len(idstring) < 7:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1023 idstring = "0" + idstring
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1024
32
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
1025 isprivate = data['view_state']['name'] == 'private'
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1026 reporter = data['reporter']['name'] if hasattr (data['reporter'], 'name') else '<nobody>'
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1027
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1028 for channel in self.cfg['channels']:
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1029 if 'btannounce' in channel and channel['btannounce'] == True:
32
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
1030 if not isprivate or ('btprivate' in channel and channel['btprivate'] == True):
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
1031 self.write ("PRIVMSG %s :[%s] New issue %s, reported by %s: %s: %s" % \
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
1032 (channel['name'], data['project']['name'], idstring, reporter,
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
1033 data['summary'], self.get_ticket_url (idstring)))
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
1034 #fi
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
1035 #fi
88899b43810b - corrected repository handling on error: print errors with commit node and pull even when processing fails
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
1036 #done
12
e843c08ee51e - added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1037
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1038 def handle_error(self):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1039 excepterm (traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1040
62
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
1041 def restart(self):
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
1042 excepterm('')
052a8a1e3d7d - revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
1043
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1044 def privmsg (self, channel, msg):
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1045 self.write ("PRIVMSG %s :%s" % (channel, msg))
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1046
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1047 def close_connection (self, message):
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
1048 if self.flags & CLIF_CONNECTED:
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1049 self.write ("QUIT :" + message)
5
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
1050 self.send_all_now()
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
1051 self.close()
b6d2b7de0a6d - added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents: 4
diff changeset
1052
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1053 def quit_irc (self):
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1054 self.close_connection ('Leaving')
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1055
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1056 def exceptdie (self):
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1057 self.close_connection ('Caught exception')
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1058
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1059 def keyboardinterrupt (self):
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1060 self.close_connection ('KeyboardInterrupt')
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1061
1
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
1062 #
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
1063 # Main procedure:
29c7e9d13a30 - fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
1064 #
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1065 try:
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1066 for aconn in g_config['autoconnect']:
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1067 for conndata in g_config['connections']:
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1068 if conndata['name'] == aconn:
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1069 irc_client (conndata, 0)
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1070 break
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1071 else:
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1072 raise logical_exception ("unknown autoconnect entry %s" % (aconn))
29
5767ee263b12 - now is able to track zandronum mercurial repositories and react to 'fixes 0001234' trigger messages in them
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
1073
26
580a2a9fd2e5 - made cobalt die if autoconnect entries cannot be found plus other stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
1074 g_BotActive = True
0
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1075 asyncore.loop()
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1076 except KeyboardInterrupt:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1077 for client in g_clients:
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1078 client.keyboardinterrupt()
4904744b40eb - initial commit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1079 quit()

mercurial