Source

turtl / turtl / config.py

from yaml import load

def loadConfigFromFile(filepath):
    """
    Load the configuration options from a filepath

    @param filepath: The filepath to a configuration file.
    @type filepath: C{twisted.python.filepath.FilePath}
    """
    return loadConfigFromString(filepath.getContent())

def loadConfigFromString(s):
    """
    Load the configuration options from a string.

    @param s: a C{str} that contains the yaml formatted
                    configuration
    @type s: yaml formatted C{str}

    @returns: a tuple of hostname and L{engine.ThrottlingDeferred}s
                and the default behavior for unknown urls.
    """
    from turtl import engine

    loaded = load(s)

    # Remove the filtering param
    rest = loaded.pop('filter-rest', True)
    port = loaded.pop('port', 8080)
    # Remove the defaults to use them as
    # a base to work on.
    defaults = loaded.pop('defaults', {})
    # If nothing is in the config file, this is the default
    defaults.update({'calls': 1, 'interval': 1, 'concurrency': 10})

    urlmapping = {}
    for host, kwargs in loaded.iteritems():
        # Fill an empty dictionary with the defaults
        # And then override the defaults with the one
        # in the current block so that we use them
        kw = {}
        kw.update(defaults)
        kw.update(kwargs)
        urlmapping[host] = engine.ThrottlingDeferred(**kw)

    return urlmapping, rest, port
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.