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"
13 opts, _ = getopt(argv[1:], "c:d")
15 conf = readconfig(opts["-c"] if "-c" in opts else CONF)
17 log.addHandler(StreamHandler(stderr))
19 log.addHandler(SysLogHandler(address="/dev/log"))
20 log.setLevel(DEBUG if "-d" in opts else INFO)
21 log.info("starting with options: %s", opts)
24 def readconfig(fname):
25 config = ConfigParser()
26 config["collector"] = {
33 #_print_config(config)
34 #print("now reading", fname)
36 #_print_config(config)
39 if __name__ == "__main__":
42 def _print_config(conf):
43 for section in conf.sections():
44 print("section", section)
45 for option in conf.options(section):
46 print(" ", option, conf[section][option])
48 conf = readconfig(argv[1])
50 print("binaryswitch", int(conf.get("device", "binaryswitch"), 0))