Exemplo n.º 1
0
def handle_save(bot, ievent):
    """ save bot data to disk """

    ievent.reply('saving')
    plugins.save()
    fleet.save()
    config.save()
    ievent.reply('done')
Exemplo n.º 2
0
def handle_save(bot, ievent):

    """ save bot data to disk """

    ievent.reply('saving')
    plugins.save()
    fleet.save()
    config.save()
    ievent.reply('done')
Exemplo n.º 3
0
def handle_loglist(bot, ievent):
    """ loglist <plugin> .. get or set loglist .. loglist is a list of plugins 
        to log.
    """

    if config['loglist'] == None:
        config['loglist'] = []

    for plugin in ievent.args:
        if plugin not in config['loglist']:
            config['loglist'].append(plugin)
        if plugin not in gozerbot.utils.log.loglist:
            gozerbot.utils.log.loglist.append(plugin)
        config.save()

    ievent.reply('loglist is now %s' % config['loglist'])
Exemplo n.º 4
0
def handle_loglist(bot, ievent):

    """ loglist <plugin> .. get or set loglist .. loglist is a list of plugins 
        to log.
    """

    if config['loglist'] == None:
        config['loglist'] = []

    for plugin in ievent.args:
        if plugin not in config['loglist']:
            config['loglist'].append(plugin)
        if plugin not in gozerbot.utils.log.loglist:
            gozerbot.utils.log.loglist.append(plugin)
        config.save()

    ievent.reply('loglist is now %s' % config['loglist'])
Exemplo n.º 5
0
def geturi(ddir=None, mainconfig=None):

    """  determine database URI from config file """

    d = ddir or datadir

    # set config file
    if mainconfig:
        config = mainconfig 
    else:
        from gozerbot.config import config

    # if dburi not provided in config file construct it
    if not config['dburi']:

        if not 'sqlite' in config['dbtype'] and not 'mysql' in config['dbtype']:
            dburi = "%s://%s:%s@%s/%s" % (config['dbtype'], config['dbuser'], \
config['dbpasswd'], config['dbhost'], config['dbname'])
        elif 'mysql' in config['dbtype']:
            dburi = "%s://%s:%s@%s/%s?charset=utf8&use_unicode=0" % (config['dbtype'], config['dbuser'], \
config['dbpasswd'], config['dbhost'], config['dbname'])
        else:
            if not os.path.isdir(d + os.sep + 'db'):
                os.mkdir(d + os.sep + 'db')
            dburi = "sqlite:///%s/%s" % (ddir or datadir, config['dbname'])

    else:
        # dburi found in config
        dburi = config['dburi']

        # determine dbtype
        try:
            dbtype = dburi.split(':')[0]
        except:
            rlog(10, 'alchemy', "can't extract db data from dburi")
            dbtype = 'unknown'

        # save dbtype
        if config['dbtype'] != dbtype:
            config['dbtype'] = dbtype
            config.save()

    return dburi
Exemplo n.º 6
0
def geturi(ddir=None, mainconfig=None):
    """  determine database URI from config file """

    d = ddir or datadir

    # set config file
    if mainconfig:
        config = mainconfig
    else:
        from gozerbot.config import config

    # if dburi not provided in config file construct it
    if not config['dburi']:

        if not 'sqlite' in config['dbtype'] and not 'mysql' in config['dbtype']:
            dburi = "%s://%s:%s@%s/%s" % (config['dbtype'], config['dbuser'], \
config['dbpasswd'], config['dbhost'], config['dbname'])
        elif 'mysql' in config['dbtype']:
            dburi = "%s://%s:%s@%s/%s?charset=utf8&use_unicode=0" % (config['dbtype'], config['dbuser'], \
config['dbpasswd'], config['dbhost'], config['dbname'])
        else:
            if not os.path.isdir(d + os.sep + 'db'):
                os.mkdir(d + os.sep + 'db')
            dburi = "sqlite:///%s/%s" % (ddir or datadir, config['dbname'])

    else:
        # dburi found in config
        dburi = config['dburi']

        # determine dbtype
        try:
            dbtype = dburi.split(':')[0]
        except:
            rlog(10, 'alchemy', "can't extract db data from dburi")
            dbtype = 'unknown'

        # save dbtype
        if config['dbtype'] != dbtype:
            config['dbtype'] = dbtype
            config.save()

    return dburi
Exemplo n.º 7
0
def handle_loglistdel(bot, ievent):
    """ loglist-del <plugin> .. delete plugin from loglist. """

    if config['loglist'] == None:
        config['loglist'] = []

    for plugin in ievent.args:

        try:
            config['loglist'].remove(plugin)
        except ValueError:
            pass

        try:
            gozerbot.utils.log.loglist.remove(plugin)
        except ValueError:
            pass

        config.save()

    ievent.reply('loglist is now %s' % config['loglist'])
Exemplo n.º 8
0
def handle_loglistdel(bot, ievent):

    """ loglist-del <plugin> .. delete plugin from loglist. """

    if config['loglist'] == None:
        config['loglist'] = []

    for plugin in ievent.args:

        try:
            config['loglist'].remove(plugin)
        except ValueError:
            pass

        try:
            gozerbot.utils.log.loglist.remove(plugin)
        except ValueError:
            pass

        config.save()

    ievent.reply('loglist is now %s' % config['loglist'])