INNER CODE UNIT · Python

parse_settings

piku/piku · piku.py:364

def parse_settings(filename, env={}):
    """Parses a settings file and returns a dict with environment variables"""

    if not exists(filename):
        return {}

    with open(filename, 'r') as settings:
        for line in settings:
            if line[0] == '#' or len(line.strip()) == 0:  # ignore comments and newlines
                continue
            try:
                k, v = map(lambda x: x.strip(), line.split("=", 1))
                env[k] = expandvars(v, env)
            except Exception:
                echo("Error: malformed setting '{}', ignoring file.".format(line), fg='red')
                return {}
    return env

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…