12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #! /usr/bin/env python
-
- import ConfigParser
- import sys
-
- class Config:
- general = {}
-
- def __init__(self, path=""):
- if path == "":
- path = "/etc/fake-tracker.conf"
- if sys.platform == "win32":
- path = "./fake-tracker.conf"
- configParser = ConfigParser.ConfigParser()
- configParser.read(path)
- try:
- self.general = self.configSectionMap(configParser, "General")
- except:
- self.general = {'maxratio' : 1,
- "maxrate" : 120,
- "torrentspath" : "."}
-
- def configSectionMap(self, configParser, section):
- dict1 = {}
- options = configParser.options(section)
- for option in options:
- try:
- dict1[option] = configParser.get(section, option)
- except:
- dict1[option] = None
- return dict1
-
- def getOption(self, option):
- try:
- return self.general[option]
- except:
- return None
-
- def getMaxRatio(self):
- return int(self.getOption('maxratio'))
-
- def getMaxRate(self):
- return int(self.getOption('maxrate'))
-
- def getTorrentsPath(self):
- return str(self.getOption('torrentspath'))
|