36 import configfile as ConfigFile |
36 import configfile as ConfigFile |
37 from configfile import Config |
37 from configfile import Config |
38 import hgpoll as HgPoll |
38 import hgpoll as HgPoll |
39 import bt as Bt |
39 import bt as Bt |
40 import irc as Irc |
40 import irc as Irc |
41 import rest as Rest |
41 import rest |
42 |
42 |
43 if __name__ != '__main__': |
43 if __name__ != '__main__': |
44 raise ImportError ('cobalt may not be imported as a module') |
44 raise ImportError ('cobalt may not be imported as a module') |
|
45 |
|
46 if sys.version_info < (3, 0): |
|
47 print ('''cobalt requires Python 3 to run''', file=sys.stderr) |
|
48 quit (1) |
45 |
49 |
46 g_BotActive = False |
50 g_BotActive = False |
47 |
51 |
48 # |
52 # |
49 # Exception handling |
53 # Exception handling |
50 # |
54 # |
51 def handle_exception(excType, excValue, trace): |
55 def handle_exception (excType, excValue, trace): |
52 excepterm (traceback.format_exception(excType, excValue, trace)) |
56 excepterm (traceback.format_exception(excType, excValue, trace)) |
53 |
57 |
54 def excepterm (data): |
58 def excepterm (data): |
55 for segment in data: |
59 for segment in data: |
56 for line in segment.splitlines(): |
60 for line in segment.splitlines(): |
57 #print line |
61 #print line |
58 Irc.broadcast (line) |
62 Irc.broadcast (line) |
59 |
63 |
60 for client in Irc.all_clients: |
64 for client in Irc.all_clients: |
61 if len(data) > 0: |
65 if data: |
62 client.exceptdie() |
66 client.exceptdie() |
63 else: |
67 else: |
64 client.quit_irc() |
68 client.quit_irc() |
65 |
69 |
66 if g_BotActive: |
70 if g_BotActive: |
102 if conndata.get_value ('name') == aconn: |
104 if conndata.get_value ('name') == aconn: |
103 Irc.irc_client (conndata, 0) |
105 Irc.irc_client (conndata, 0) |
104 break |
106 break |
105 else: |
107 else: |
106 raise ValueError ('unknown autoconnect entry "%s"' % (aconn)) |
108 raise ValueError ('unknown autoconnect entry "%s"' % (aconn)) |
107 |
109 |
108 # Start the REST server |
|
109 if Config.get_node ('rest').get_value ('active', True): |
110 if Config.get_node ('rest').get_value ('active', True): |
110 Rest.RESTServer() |
111 rest.RestServer() |
111 |
112 |
112 g_BotActive = True |
113 g_BotActive = True |
113 asyncore.loop() |
114 asyncore.loop() |
114 except KeyboardInterrupt: |
115 except KeyboardInterrupt: |
115 for client in Irc.all_clients: |
116 for client in Irc.all_clients: |