Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'universal_exceptions'

Conflicts:
	ircSocket.py
  • Loading branch information...
commit 5a7b0a1077c37bc771d6040036c1b1aa7273f1fc 2 parents 4ef1e83 + f32b2e5
@richo richo authored
View
14 config.py
@@ -8,11 +8,8 @@
import logging
import os
+from lib import *
-class InvalidConfig(Exception):
- pass
-class NoConfigFile(Exception):
- pass
CONFIG_FILE = 'pyBawt.conf'
@@ -56,7 +53,7 @@ def passthru(val):
continue
try:
key, value = map(lambda x: x.strip(),line.split('=', 1))
- config[key] = value
+ config[key] = (value, lineno)
except ValueError:
raise InvalidConfig, "Invalid key value pair at line %i" % (lineno)
except IOError:
@@ -68,12 +65,11 @@ def passthru(val):
for name, transformer in keys:
__all__.append(name)
try:
- # This is fucked XXX FIXME
- #__dict__[name] = transformer(config[name])
- exec('%s = %s' % (name, repr(transformer(config[name]))))
+ val, line = config[name]
+ exec('%s = %s' % (name, repr(transformer(val))))
except ValueError: #Probably port didn't translate
# Pull lineno, spit out useful error
- raise InvalidConfig
+ raise InvalidConfig, "Counldn't parse %s on line %i" % (val, line)
except KeyError: #Didn't have a required key
raise InvalidConfig, "Missing required key: %s" % (name)
View
18 ircSocket.py
@@ -1,3 +1,4 @@
+from lib import *
import threading
import socket
import sys
@@ -13,21 +14,6 @@
import auth
import logging
-class ModuleError(Exception):
- pass
-
-class IrcDisconnected(Exception):
- pass
-
-class IrcTerminated(Exception):
- pass
-class FlushQueue(Exception):
- """ Flush the event queue, don't wait for IO"""
- pass
-class ModulesDidntLoadDueToSyntax(Exception):
- def __nonzero__(self):
- # This allows us to retain the logical "if status" test.
- return False
def should_reconnect():
"""This hook lies in here because it'll give the rest of the structure a fairly central place
@@ -542,7 +528,7 @@ def do_chores(self):
try:
# TODO - implement a signal stop
i.handle(msg)
- except bModules.StopHandling:
+ except StopHandling:
break
def SockConnect(host, port, use_ssl):
View
31 lib.py
@@ -15,3 +15,34 @@ def lower(n):
return n
def __contains__(self, value):
return self.lower(value) in map(self.lower, self)
+
+# Put all exceptions in lib.py
+
+class ModuleError(Exception):
+ pass
+
+class IrcDisconnected(Exception):
+ pass
+
+class IrcTerminated(Exception):
+ pass
+class FlushQueue(Exception):
+ """ Flush the event queue, don't wait for IO"""
+ pass
+class ModulesDidntLoadDueToSyntax(Exception):
+ def __nonzero__(self):
+ # This allows us to retain the logical "if status" test.
+ return False
+
+class Restart(Exception):
+ pass
+class StopHandling(Exception):
+ pass
+
+class ModuleAlreadyLoaded(Exception):
+ pass
+
+class InvalidConfig(Exception):
+ pass
+class NoConfigFile(Exception):
+ pass
View
7 modules.d/000_core.py
@@ -7,6 +7,8 @@
import sys
import logging
+from lib import *
+
VERSION="$Rev: 1252 $".split(" ")[1]
def get_help(mdl):
@@ -22,11 +24,6 @@ def get_help(mdl):
# CORE
#-----
-class Restart(Exception):
- pass
-class StopHandling(Exception):
- pass
-
class BawtM2(object):
"""I'm a lazy programmer who doesn't write help files"""
View
4 modules.d/core_modules.py
@@ -5,14 +5,10 @@
import sys
import atexit
import traceback
-from lib import *
import logging
VERSION="$Rev: 1252 $".split(" ")[1]
-class ModuleAlreadyLoaded(Exception):
- pass
-
# TODO Split this out into core modules, and then import a set of user added
# ones. BawtM2 and the stuff to do reloads is all that needs to be global
# TODO Work out how the channel infrastructure will work (structured
View
17 pyBawt.py
@@ -11,17 +11,22 @@
##
# Rich Healey '08
+from lib import *
+import logging
+try:
+ import config
+except InvalidConfig as e:
+ logging.fatal("Couldn't load config file: %s" % (str(e)))
import ircSocket
import time
import sys
import os
import random
-import config
import bModules
-import logging
import traceback
+
logging.info("pyBawt started")
# Have a crack at sweet argparsing
@@ -67,20 +72,20 @@ def restart_stub():
while True:
try:
net.recv_wait()
- except ircSocket.FlushQueue:
+ except FlushQueue:
pass
net.dump_queue()
except KeyboardInterrupt:
logging.error("Shutting down due to user intervention")
net.quit("Killed from terminal")
-except bModules.Restart:
+except Restart:
# TODO Include the user who did this
logging.error("Restarting due to user intervention")
restart_stub()
-except ircSocket.IrcDisconnected:
+except IrcDisconnected:
if ircSocket.should_reconnect():
restart_stub()
-except ircSocket.IrcTerminated:
+except IrcTerminated:
# Catch but don't handle, die gracefully
pass
except Exception:
Please sign in to comment.
Something went wrong with that request. Please try again.