Beispiel #1
0
    def do_reload(self, c, target, cmdargs):
        """The reloading magic.

        | First, reload handler.py.
        | Then make copies of all the handler data we want to keep.
        | Create a new handler and restore all the data.
        """
        self.reload_event.clear()
        output = None
        if cmdargs == 'pull':
            output = misc.do_pull(dirname(__file__), c.real_nickname)
            c.privmsg(target, output)
        for name in modutils.get_enabled('helpers', 'helpers')[0]:
            if name in sys.modules:
                importlib.reload(sys.modules[name])
        importlib.reload(handler)
        self.config = ConfigParser()
        configfile = join(dirname(__file__), 'config.cfg')
        with open(configfile) as cfgfile:
            self.config.read_file(cfgfile)
        # preserve data
        data = self.handler.get_data()
        self.shutdown_server()
        self.shutdown_workers()
        self.handler = handler.BotHandler(self.config)
        self.handler.set_data(data)
        self.handler.connection = c
        self.handler.channels = self.channels
        if self.config['feature'].getboolean('server'):
            self.server = server.init_server(self)
        self.reload_event.set()
        if output:
            return output
Beispiel #2
0
    def do_reload(self, c, target, cmdargs, msgtype):
        """The reloading magic.

        | First, reload handler.py.
        | Then make copies of all the handler data we want to keep.
        | Create a new handler and restore all the data.
        """
        output = None
        if cmdargs == 'pull':
            output = misc.do_pull(dirname(__file__), c.real_nickname)
            c.privmsg(target, output)
        for x in modutils.get_enabled(dirname(__file__) + '/helpers'):
            name = 'helpers.%s' % x
            if name in sys.modules:
                importlib.reload(sys.modules[name])
        importlib.reload(handler)
        self.config = ConfigParser()
        configfile = join(dirname(__file__), 'config.cfg')
        self.config.read_file(open(configfile))
        # preserve data
        data = self.handler.get_data()
        self.do_shutdown(True)
        self.handler = handler.BotHandler(self.config)
        if self.config['feature'].getboolean('server'):
            self.server = server.init_server(self)
        self.handler.set_data(data)
        self.handler.connection = c
        self.handler.channels = self.channels
        self.handler.workers = workers.Workers(self.handler)
        if output:
            return output
Beispiel #3
0
    def do_reload(self, c, target, cmdargs, msgtype):
        """The reloading magic.

        | First, reload handler.py.
        | Then make copies of all the handler data we want to keep.
        | Create a new handler and restore all the data.
        """
        output = None
        if cmdargs == 'pull':
            output = misc.do_pull(dirname(__file__), c.real_nickname)
            c.privmsg(target, output)
        for x in modutils.get_enabled(dirname(__file__) + '/helpers'):
            name = 'helpers.%s' % x
            if name in sys.modules:
                importlib.reload(sys.modules[name])
        importlib.reload(handler)
        self.config = ConfigParser()
        configfile = join(dirname(__file__), 'config.cfg')
        self.config.read_file(open(configfile))
        # preserve data
        data = self.handler.get_data()
        self.do_shutdown(True)
        self.handler = handler.BotHandler(self.config)
        if self.config['feature'].getboolean('server'):
            self.server = server.init_server(self)
        self.handler.set_data(data)
        self.handler.connection = c
        self.handler.channels = self.channels
        self.handler.workers = workers.Workers(self.handler)
        if output:
            return output
Beispiel #4
0
def cmd(send, _, args):
    """Pull changes.
    Syntax: {command} <branch>
    """
    try:
        send(do_pull(args['handler'].srcdir, args['botnick']))
    except subprocess.CalledProcessError as e:
        for line in e.output.decode().splitlines():
            send(line)
Beispiel #5
0
def cmd(send, msg, args):
    """Pull changes.
    Syntax: {command} <branch>
    """
    if not args['is_admin'](args['nick']):
        send("Nope, not gonna do it.")
    else:
        try:
            send(do_pull(args['handler'].srcdir, args['botnick']))
        except subprocess.CalledProcessError as e:
            for line in e.output.decode().splitlines():
                send(line)
Beispiel #6
0
def cmd(send, msg, args):
    """Pull changes.
    Syntax: !pull <branch>
    """
    if not args['is_admin'](args['nick']):
        send("Nope, not gonna do it.")
    else:
        try:
            send(do_pull(args['handler'].srcdir, args['botnick']))
        except subprocess.CalledProcessError as e:
            for line in e.output.decode().splitlines():
                send(line)
Beispiel #7
0
    def do_reload(self, c, target, cmdargs):
        """The reloading magic.

        | First, reload handler.py.
        | Then make copies of all the handler data we want to keep.
        | Create a new handler and restore all the data.
        """
        self.reload_event.clear()
        output = None
        if cmdargs == 'pull':
            srcdir = dirname(abspath(__file__))
            output = misc.do_pull(srcdir, c.real_nickname)
            c.privmsg(target, output)
        reload_ok = True
        failed_modules = []
        for name in modutils.get_enabled('helpers', 'helpers')[0]:
            if name in sys.modules:
                mod_reload_ok = modutils.safe_reload(sys.modules[name])
                if not mod_reload_ok:
                    failed_modules.append(name)
                    reload_ok = False
        if not reload_ok:
            controlchan = self.config['core']['ctrlchan']
            self.connection.privmsg(controlchan,
                                    "Failed to reload some helper modules. Some commands may not work as expected, see the console for details")
            self.connection.privmsg(controlchan, "Failures: " + ", ".join(failed_modules))
        modutils.safe_reload(handler)
        self.config = ConfigParser()
        configfile = join(dirname(__file__), 'config.cfg')
        with open(configfile) as cfgfile:
            self.config.read_file(cfgfile)
        # preserve data
        data = self.handler.get_data()
        self.shutdown_mp()
        self.handler = handler.BotHandler(self.config)
        self.handler.set_data(data)
        self.handler.connection = c
        self.handler.channels = self.channels
        if self.config['feature'].getboolean('server'):
            self.server = server.init_server(self)
        self.reload_event.set()
        if output:
            return output
Beispiel #8
0
def do_reload(bot, target, cmdargs, server_send=None):
    """The reloading magic.

    | First, reload handler.py.
    | Then make copies of all the handler data we want to keep.
    | Create a new handler and restore all the data.
    """
    def send(msg):
        if server_send is not None:
            server_send(msg)
        else:
            do_log(bot.connection, target, msg)

    if cmdargs == 'pull':
        srcdir = path.dirname(path.abspath(__file__))
        send(misc.do_pull(srcdir, bot.connection.real_nickname))
    # Reimport helpers
    errored_helpers = modutils.scan_and_reimport('helpers', 'helpers')
    if errored_helpers:
        send("Failed to load some helpers.")
        for error in errored_helpers:
            send("%s: %s" % error)
        return False
    if not load_modules(bot.config, send):
        return False

    bot.config = configparser.ConfigParser(
        interpolation=configparser.ExtendedInterpolation())
    config_file = path.join(path.dirname(__file__), '../config.cfg')
    with open(config_file) as f:
        bot.config.read_file(f)
    # preserve data
    data = bot.handler.get_data()
    bot.shutdown_mp()
    bot.handler = handler.BotHandler(bot.config, bot.connection, bot.channels)
    bot.handler.set_data(data)
    bot.handler.connection = bot.connection
    bot.handler.channels = bot.channels
    return True
Beispiel #9
0
def do_reload(bot, target, cmdargs, server_send=None):
    """The reloading magic.

    | First, reload handler.py.
    | Then make copies of all the handler data we want to keep.
    | Create a new handler and restore all the data.
    """
    def send(msg):
        if server_send is not None:
            server_send(msg)
        else:
            do_log(bot.connection, target, msg)

    if cmdargs == 'pull':
        srcdir = path.dirname(path.abspath(__file__))
        send(misc.do_pull(srcdir, bot.connection.real_nickname))
    # Reimport helpers
    errored_helpers = modutils.scan_and_reimport('helpers', 'helpers')
    if errored_helpers:
        send("Failed to load some helpers.")
        for error in errored_helpers:
            send("%s: %s" % error)
        return False
    if not load_modules(bot.config, send):
        return False

    bot.config = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
    config_file = path.join(path.dirname(__file__), '../config.cfg')
    with open(config_file) as f:
        bot.config.read_file(f)
    # preserve data
    data = bot.handler.get_data()
    bot.shutdown_mp()
    bot.handler = handler.BotHandler(bot.config, bot.connection, bot.channels)
    bot.handler.set_data(data)
    bot.handler.connection = bot.connection
    bot.handler.channels = bot.channels
    return True