config Package

config Package

class earwigbot.config.BotConfig(bot, root_dir, level)[source]

EarwigBot: YAML Config File Manager

This handles all tasks involving reading and writing to our config file, including encrypting and decrypting passwords and making a new config file from scratch at the inital bot run.

BotConfig has a few attributes and methods, including the following:

  • root_dir: bot’s working directory; contains config.yml, logs/
  • path: path to the bot’s config file
  • components: enabled components
  • wiki: information about wiki-editing
  • irc: information about IRC
  • commands: information about IRC commands
  • tasks: information for bot tasks
  • metadata: miscellaneous information
  • schedule(): tasks scheduled to run at a given time

BotConfig also has some methods used in config loading:

  • load(): loads (or reloads) and parses our config file
  • decrypt(): decrypts an object in the config tree
bot[source]

The config’s Bot object.

commands[source]

A dict of information for IRC commands.

components[source]

A dict of enabled components.

data[source]

The entire config file as a decoded JSON object.

decrypt(node, *nodes)[source]

Decrypt an object in our config tree.

_decryption_cipher is used as our key, retrieved using getpass() in load() if it wasn’t already specified. If this is called when passwords are not encrypted (check with is_encrypted()), nothing will happen. We’ll also keep track of this node if load() is called again (i.e. to reload) and automatically decrypt it.

Example usage:

>>> config.decrypt(config.irc, "frontend", "nickservPassword")
# decrypts config.irc["frontend"]["nickservPassword"]
irc[source]

A dict of information about IRC.

is_encrypted()[source]

Return True if passwords are encrypted, otherwise False.

is_loaded()[source]

Return True if our config file has been loaded, or False.

load()[source]

Load, or reload, our config file.

First, check if we have a valid config file, and if not, notify the user. If there is no config file at all, offer to make one, otherwise exit.

Data from the config file is stored in six ConfigNodes (components, wiki, irc, commands, tasks, metadata) for easy access (as well as the lower-level data attribute). If passwords are encrypted, we’ll use getpass() for the key and then decrypt them. If the config is being reloaded, encrypted items will be automatically decrypted if they were decrypted earlier.

log_dir[source]

The directory containing the bot’s logs.

logging_level[source]

The minimum logging level for messages logged via stdout.

metadata[source]

A dict of miscellaneous information.

path[source]

The path to the bot’s config file.

root_dir[source]

The bot’s root directory containing its config file and more.

schedule(minute, hour, month_day, month, week_day)[source]

Return a list of tasks scheduled to run at the specified time.

The schedule data comes from our config file’s schedule field, which is stored as self.data["schedule"].

tasks[source]

A dict of information for bot tasks.

wiki[source]

A dict of information about wiki-editing.

formatter Module

class earwigbot.config.formatter.BotFormatter(color=False)[source]

Bases: logging.Formatter

format_color(record)[source]

node Module

class earwigbot.config.node.ConfigNode[source]
get(*args, **kwargs)[source]
items()[source]
iteritems()[source]
iterkeys()[source]
itervalues()[source]
keys()[source]
values()[source]

ordered_yaml Module

Based on:

with modifications.

class earwigbot.config.ordered_yaml.OrderedLoader(*args, **kwargs)[source]

Bases: yaml.loader.Loader

A YAML loader that loads mappings into ordered dictionaries.

construct_mapping(node, deep=False)[source]
construct_yaml_map(node)[source]
class earwigbot.config.ordered_yaml.OrderedDumper(*args, **kwargs)[source]

Bases: yaml.dumper.SafeDumper

A YAML dumper that dumps ordered dictionaries into mappings.

represent_mapping(tag, mapping, flow_style=None)[source]

permissions Module

class earwigbot.config.permissions.PermissionsDB(dbfile)[source]

EarwigBot: Permissions Database Manager

Controls the permissions.db file, which stores the bot’s owners and admins for the purposes of using certain dangerous IRC commands.

ADMIN = 1
OWNER = 2
add_admin(nick='*', ident='*', host='*')[source]

Add a nick/ident/host combo to the bot admins list.

add_owner(nick='*', ident='*', host='*')[source]

Add a nick/ident/host combo to the bot owners list.

attributes[source]

A dict of all attributes in the permissions database.

get_attr(user, key)[source]

Get the value of the attribute key of a given user.

Raises KeyError if the key or user is not found.

has_attr(user, key)[source]

Return True if a given user has a certain attribute, key.

has_exact(rank, nick='*', ident='*', host='*')[source]

Return True if there is an exact match for this rule.

is_admin(data)[source]

Return True if the given user is a bot admin, else False.

is_owner(data)[source]

Return True if the given user is a bot owner, else False.

load()[source]

Load permissions from an existing database, or create a new one.

remove_admin(nick='*', ident='*', host='*')[source]

Remove a nick/ident/host combo to the bot admins list.

remove_attr(user, key)[source]

Remove the attribute key of a given user.

remove_owner(nick='*', ident='*', host='*')[source]

Remove a nick/ident/host combo to the bot owners list.

set_attr(user, key, value)[source]

Set the value of the attribute key of a given user.

users[source]

A dict of all users in the permissions database.

script Module

class earwigbot.config.script.ConfigScript(config)[source]

A script to guide a user through the creation of a new config file.

BCRYPT_ROUNDS = 12
PROMPT = '\x1b[32m> \x1b[0m'
WIDTH = 79
make_new()[source]

Make a new config file based on the user’s input.

Table Of Contents

Previous topic

commands Package

Next topic

irc Package

This Page