Exemplo n.º 1
0
    def run(self):
        # Import elements of Core we need
        # These will be refreshed each time the Loader reloads
        from Core.loader import Loader
        from Core.exceptions_ import Quit, Reboot, Reload, Call999
        from Core.connection import Connection
        from Core.chanusertracker import CUT
        from Core.robocop import RoboCop
        from Core.router import Router
	from Core.actions import Action
        
        # Collect any garbage remnants that might have been left behind
        #  from an old loader or backup that wasn't properly dereferenced
        gc.collect()
        
        try:

            # Attach the IRC connection and configure
            self.irc = Connection.attach(*self.irc)
            # Attach the RoboCop/clients sockets and configure
            self.robocop = RoboCop.attach(*self.robocop)
            # Attach the CUT state
            self.cut = CUT.attach(*self.cut)
            
            # Operation loop
            Router.run()
        
        except Call999 as exc:
            # RoboCop server failed, restart it
            self.robocop = RoboCop.disconnect(str(exc))
            return
        
        except Reboot as exc:
            # Reset the connection first
            self.irc = Connection.disconnect(str(exc) or "Rebooting")
            print "%s Reloading..." % (time.asctime(),)
            # Reimport all the modules
            Loader.reload()
            return
        
        except Reload:
            # Detach the current CUT state
            self.cut = CUT.detach()
            print "%s Reloading..." % (time.asctime(),)
            # Reimport all the modules
            Loader.reload()
            return
        
        except (Quit, KeyboardInterrupt, SystemExit) as exc:
            self.irc = Connection.disconnect(str(exc) or "Bye!")
            self.robocop = RoboCop.disconnect(str(exc) or "Bye!")
            sys.exit("Bye!")
Exemplo n.º 2
0
    def run(self):
        # Import elements of Core we need
        # These will be refreshed each time the Loader reloads
        from Core.loader import Loader
        from Core.exceptions_ import Quit, Reboot, Reload, Call999
        from Core.connection import Connection
        from Core.chanusertracker import CUT
        from Core.robocop import RoboCop
        from Core.router import Router

        # Collect any garbage remnants that might have been left behind
        #  from an old loader or backup that wasn't properly dereferenced
        gc.collect()

        try:
            # Attach the IRC connection and configure
            self.irc = Connection.attach(*self.irc)
            # Attach the RoboCop/clients sockets and configure
            self.robocop = RoboCop.attach(*self.robocop)
            # Attach the CUT state
            self.cut = CUT.attach(*self.cut)

            # Operation loop
            Router.run()

        except Call999 as exc:
            # RoboCop server failed, restart it
            self.robocop = RoboCop.disconnect(str(exc))
            return

        except Reboot as exc:
            # Reset the connection first
            self.irc = Connection.disconnect(str(exc) or "Rebooting")
            print "%s Reloading..." % (time.asctime(), )
            # Reimport all the modules
            Loader.reload()
            return

        except Reload:
            # Detach the current CUT state
            self.cut = CUT.detach()
            print "%s Reloading..." % (time.asctime(), )
            # Reimport all the modules
            Loader.reload()
            return

        except (Quit, KeyboardInterrupt, SystemExit) as exc:
            self.irc = Connection.disconnect(str(exc) or "Bye!")
            self.robocop = RoboCop.disconnect(str(exc) or "Bye!")
            sys.exit("Bye!")