]> www.average.org Git - loctrkd.git/blob - gps303/config.py
introduce config
[loctrkd.git] / gps303 / config.py
1 from configparser import ConfigParser
2
3 PORT = 4303
4 DBFN = "/var/lib/gps303/gps303.sqlite"
5
6 def readconfig(fname):
7     config = ConfigParser()
8     config.read(fname)
9     if not config.has_section("daemon"):
10         config.add_section("daemon")
11     if not config.has_option("daemon", "port"):
12         config["daemon"]["port"] = str(PORT)
13     if not config.has_option("daemon", "dbfn"):
14         config["daemon"]["dbfn"] = DBFN
15     return config
16
17 if __name__ == "__main__":
18     from sys import argv
19     conf = readconfig(argv[1])
20     for section in conf.sections():
21         print("section", section)
22         for option in conf.options(section):
23             print("    ", option, conf[section][option])
24     print("binaryswitch", int(conf.get("device", "binaryswitch"), 0))