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")
|