Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 49 lines (45 sloc) 1.747 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
"""
A reader for the simple .pry config file format. The format is as follows:

base = basedirectory
coverage = coveragedirectory
exclude = newline separated
paths excluded
from coverage

The special _magic flag is needed to allow pry to run coverage analysis on
itsef.
"""
import ConfigParser, cStringIO, os.path

class Config:
    _valid = set(["base", "coverage", "exclude", "_magic"])
    def __init__(self, path):
        self.path = path
        if os.path.isfile(path):
            self.c = ConfigParser.SafeConfigParser()
            data = open(path).read()
            # You know, Python is my favourite language and all, but its
            # standard library can be utterly moronic
            io = cStringIO.StringIO()
            io.write("[pry]\n")
            io.write(data)
            io.reset()
            self.c.readfp(io)
            options = set(self.c.options("pry"))
            if not self._valid.issuperset(options):
                bad = options - self._valid
                bad = ",".join(list(bad))
                raise ValueError, "Unknown options in config file: %s"%bad
            items = dict(self.c.items("pry"))
            self.base = items.get("base", "..").strip()
            self.coverage = items.get("coverage", "..").strip()
            if items.has_key("_magic"):
                self._magic = True
            else:
                self._magic = False
            ex = items.get("exclude", ".")
            ex = ex.split("\n")
            self.exclude = [i.strip() for i in ex]
        else:
            self.base = ".."
            self.coverage = ".."
            self.exclude = ["."]
            self._magic = False
Something went wrong with that request. Please try again.