1 """ Common housekeeping for all daemons """
3 from configparser import ConfigParser
4 from getopt import getopt
5 from logging import getLogger, StreamHandler, DEBUG, INFO
6 from sys import argv, stderr, stdout
8 CONF = "/etc/gps303.conf"
10 DBFN = "/var/lib/gps303/gps303.sqlite"
14 opts, _ = getopt(argv[1:], "c:d")
16 conf = readconfig(opts["-c"] if "-c" in opts else CONF)
18 log.addHandler(StreamHandler(stderr))
20 log.addHandler(SysLogHandler(address="/dev/log"))
21 log.setLevel(DEBUG if "-d" in opts else INFO)
22 log.info("starting with options: %s", opts)
26 def readconfig(fname):
27 config = ConfigParser()
28 config["collector"] = {
34 config["termconfig"] = {}
39 def normconf(section):
41 for key, val in section.items():
42 vals = val.split("\n")
43 if len(vals) > 1 and vals[0] == "":
50 if el[0] == '"' and el[-1] == '"':
51 el = el.strip('"').rstrip('"')
59 if __name__ == "__main__":
62 def _print_config(conf):
63 for section in conf.sections():
64 print("section", section)
65 for option in conf.options(section):
66 print(" ", option, conf[section][option])
68 conf = readconfig(argv[1])
70 print(normconf(conf["termconfig"]))