File: DistUpgradeConfigParser.py

package info (click to toggle)
update-manager 0.68.debian-7
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,796 kB
  • ctags: 814
  • sloc: python: 5,646; xml: 1,571; sh: 433; makefile: 356; ansic: 264
file content (34 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download
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
from ConfigParser import ConfigParser, NoOptionError, NoSectionError


class DistUpgradeConfig(ConfigParser):
    def __init__(self, datadir, name="DistUpgrade.cfg"):
        ConfigParser.__init__(self)
        self.datadir=datadir
        self.read([datadir+"/"+name])
    def getWithDefault(self, section, option, default):
        try:
            return self.get(section, option)
        except (NoSectionError, NoOptionError),e:
            return default
    def getlist(self, section, option):
        try:
            tmp = self.get(section, option)
        except (NoSectionError,NoOptionError),e:
            return []
        items = [x.strip() for x in tmp.split(",")]
        return items
    def getListFromFile(self, section, option):
        try:
            filename = self.get(section, option)
        except NoOptionError:
            return []
        items = [x.strip() for x in open(self.datadir+"/"+filename)]
        return filter(lambda s: not s.startswith("#") and not s == "", items)


if __name__ == "__main__":
    c = DistUpgradeConfig()
    print c.getlist("Distro","MetaPkgs")
    print c.getlist("Distro","ForcedPurges")
    print c.getListFromFile("Sources","ValidMirrors")