Browse Source

config reader; config example

master
Robin Thoni 9 years ago
parent
commit
cdf2c64f34
2 changed files with 35 additions and 0 deletions
  1. 3
    0
      config.conf
  2. 32
    0
      config.py

+ 3
- 0
config.conf View File

@@ -0,0 +1,3 @@
1
+[General]
2
+maxRatio: 3
3
+maxRate: 120

+ 32
- 0
config.py View File

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

Loading…
Cancel
Save