#!/usr/bin/env python
"""
__init__.py - Jenni Init Module
Copyright 2008, Sean B. Palmer, inamidst.com
Licensed under the Eiffel Forum License 2.

http://inamidst.com/phenny/
"""

import sys, os, time, threading, signal
import bot

class Watcher(object):
    # Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735
    def __init__(self):
        self.child = os.fork()
        if self.child != 0:
            self.watch()

    def watch(self):
        try: os.wait()
        except KeyboardInterrupt:
            self.kill()
        sys.exit()

    def kill(self):
        try: os.kill(self.child, signal.SIGKILL)
        except OSError: pass

def run_jenni(config):
    if hasattr(config, 'delay'):
        delay = config.delay
    else: delay = 20

    def connect(config):
        p = bot.Jenni(config)
        p.run(config.host, config.port)

    try: Watcher()
    except Exception, e:
        print >> sys.stderr, 'Warning:', e, '(in __init__.py)'

    while True:
        try: connect(config)
        except KeyboardInterrupt:
            sys.exit()

        if not isinstance(delay, int):
            break

        warning = 'Warning: Disconnected. Reconnecting in %s seconds...' % delay
        print >> sys.stderr, warning
        time.sleep(delay)

def run(config):
    t = threading.Thread(target=run_jenni, args=(config,))
    if hasattr(t, 'run'):
        t.run()
    else: t.start()

if __name__ == '__main__':
    print __doc__

@@ -15,16 +15,31 @@
  python%0A
+# coding=utf-8%0A
 %22%22%22%0A__in
@@ -48,21 +48,22 @@
 __.py - 
-Jenni
+Willie
  Init Mo
@@ -112,16 +112,125 @@
 dst.com%0A
+Copyright 2012, Edward Powell, http://embolalia.net%0ACopyright %C2%A9 2012, Elad Alfassa %3Celad@fedoraproject.org%3E%0A%0A
 Licensed
@@ -276,27 +276,24 @@
 p://
-inamidst.com/phenny
+willie.dftba.net
 /%0A%22%22
@@ -780,22 +780,16 @@
 %0Adef run
-_jenni
 (config)
@@ -862,16 +862,25 @@
   else: 
+%0A        
 delay = 
@@ -887,104 +887,8 @@
 20%0A%0A
-    def connect(config):%0A        p = bot.Jenni(config)%0A        p.run(config.host, config.port)%0A%0A
     
@@ -1024,22 +1024,85 @@
 ry: 
-connect(
+%0A            p = bot.Jenni(config)%0A            p.run(config.host, 
 config
+.port
 )%0A  
@@ -1151,24 +1151,532 @@
   sys.exit()
+%0A        except Exception, e:%0A            import traceback%0A            trace = traceback.format_exc()%0A            try:%0A                print trace%0A            except:%0A                pass%0A            logfile = open('logs/exceptions.log', 'a') #todo: make not hardcoded%0A            logfile.write('Critical exception in core')%0A            logfile.write(e)%0A            logfile.write(trace)%0A            logfile.write('----------------------------------------%5Cn%5Cn')%0A            logfile.close()%0A            raise e
 %0A%0A        if
@@ -1800,24 +1800,41 @@
 ..' %25 delay%0A
+        try:%0A    
         prin
@@ -1870,163 +1870,57 @@
     
-time.sleep(delay)%0A%0Adef run(config):%0A    t = threading.Thread(target=run_jenni, args=(config,))%0A    if hasattr(t, 'run'):%0A        t.run()%0A    else: t.start(
+except:%0A            pass%0A        time.sleep(delay
 )%0A%0Ai

Add debugging to core exceptions, remove useless thread