Configuration utilities

Utilities for reading dogecoin configuration files.

read_config_file(filename)

Read a simple '='-delimited config file. Raises :const:IOError if unable to open file, or :const:ValueError if an parse error occurs.

Source code in dogecoinrpc/config.py
def read_config_file(filename):
    """
    Read a simple ``'='``-delimited config file.
    Raises :const:`IOError` if unable to open file, or :const:`ValueError`
    if an parse error occurs.
    """
    with open(filename) as f:
        cfg = {}
        for line in f:
            line = line.strip()
            if line and not line.startswith("#"):
                try:
                    (key, value) = line.split("=", 1)
                    cfg[key] = value
                except ValueError:
                    pass  # Happens when line has no '=', ignore
    return cfg

read_default_config(filename=None)

Read dogecoin default configuration from the current user's home directory.

  • filename: Path to a configuration file in a non-standard location (optional)
Source code in dogecoinrpc/config.py
def read_default_config(filename=None):
    """
    Read dogecoin default configuration from the current user's home directory.

    Arguments:

    - `filename`: Path to a configuration file in a non-standard location (optional)
    """
    if filename is None:
        home = str(Path.home())
        if platform.system() == "Darwin":
            location = "Library/Application Support/Dogecoin/dogecoin.conf"
        elif platform.system() in ("Windows", "Microsoft"):
            location = "AppData\\Roaming\\DogeCoin\\dogecoin.conf"
        else:
            location = ".dogecoin/dogecoin.conf"
        filename = os.path.join(home, location)

    elif filename.startswith("~"):
        filename = os.path.expanduser(filename)

    try:
        return read_config_file(filename)
    except (IOError, ValueError):
        pass  # Cannot read config file, ignore