您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

config.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #! /usr/bin/env python
  2. import ConfigParser
  3. import sys
  4. class Config:
  5. general = {}
  6. def __init__(self, path=""):
  7. if path == "":
  8. path = "/etc/fake-tracker.conf"
  9. if sys.platform == "win32":
  10. path = "./fake-tracker.conf"
  11. configParser = ConfigParser.ConfigParser()
  12. configParser.read(path)
  13. try:
  14. self.general = self.configSectionMap(configParser, "General")
  15. except:
  16. self.general = {'maxratio' : 1,
  17. "maxrate" : 120,
  18. "torrentspath" : "."}
  19. def configSectionMap(self, configParser, section):
  20. dict1 = {}
  21. options = configParser.options(section)
  22. for option in options:
  23. try:
  24. dict1[option] = configParser.get(section, option)
  25. except:
  26. dict1[option] = None
  27. return dict1
  28. def getOption(self, option):
  29. try:
  30. return self.general[option]
  31. except:
  32. return None
  33. def getMaxRatio(self):
  34. return float(self.getOption('maxratio'))
  35. def getMaxRate(self):
  36. return float(self.getOption('maxrate'))
  37. def getTorrentsPath(self):
  38. return str(self.getOption('torrentspath'))