Exception handling fixes
This commit is contained in:
parent
2d9643c946
commit
7e8e3545a4
2 changed files with 15 additions and 13 deletions
26
uplink.py
26
uplink.py
|
|
@ -30,7 +30,7 @@ import time
|
||||||
from uplink.uplink import Uplink
|
from uplink.uplink import Uplink
|
||||||
|
|
||||||
# Version format: MAJOR.FEATURE.FIXES
|
# Version format: MAJOR.FEATURE.FIXES
|
||||||
__version__ = "0.4.0-development"
|
__version__ = "0.4.1-development"
|
||||||
|
|
||||||
# TODO: CHECK ALL ERROR HANDLING!!!
|
# TODO: CHECK ALL ERROR HANDLING!!!
|
||||||
# TODO: Implement logging
|
# TODO: Implement logging
|
||||||
|
|
@ -109,35 +109,39 @@ if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
with open(config_path, 'r') as configfile:
|
with open(config_path, 'r') as configfile:
|
||||||
config_data = configfile.read()
|
config_data = configfile.read()
|
||||||
_config = json.loads(config_data)
|
config = json.loads(config_data)
|
||||||
except "OSError, PermissionDenied, RuntimeError, ValueError" as err:
|
except "OSError, PermissionDenied, RuntimeError, ValueError" as err:
|
||||||
# TODO: Replace all lines like this with generic Python logging
|
# TODO: Replace all lines like this with generic Python logging
|
||||||
print(str("Uplink: Configuration Error!" + err))
|
print(str("Uplink: Configuration Error!" + err))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_config["interval"]
|
config["interval"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# interval not configured in configuration; using default value
|
# interval not configured in configuration; using default value
|
||||||
_config["interval"] = 60
|
config["interval"] = 60
|
||||||
|
|
||||||
if args.interval:
|
if args.interval:
|
||||||
# interval set in args is overriding configuration and default
|
# interval set in args is overriding configuration and default
|
||||||
_config["interval"] = args.interval
|
config["interval"] = args.interval
|
||||||
|
|
||||||
uplink = Uplink("/tmp/uplink.pid", _config)
|
uplink = Uplink("/tmp/uplink.pid", config)
|
||||||
|
|
||||||
if args.cron:
|
if args.cron:
|
||||||
for i in range(len(_config["uplinks"])):
|
for i in range(len(config["uplinks"])):
|
||||||
uplink.get_data(_config, i)
|
uplink.get_data(config, i)
|
||||||
elif args.daemon:
|
elif args.daemon:
|
||||||
uplink.start()
|
uplink.start()
|
||||||
elif args.foreground:
|
elif args.foreground:
|
||||||
while True:
|
while True:
|
||||||
for i in range(len(_config["uplinks"])):
|
for i in range(len(config["uplinks"])):
|
||||||
uplink.get_data(_config, i)
|
uplink.get_data(config, i)
|
||||||
# TODO: print data formatted to STDOUT
|
# TODO: print data formatted to STDOUT
|
||||||
time.sleep(_config["interval"])
|
try:
|
||||||
|
time.sleep(config["interval"])
|
||||||
|
except KeyboardInterrupt as err:
|
||||||
|
print(str("uplink: program terminated by user!"))
|
||||||
|
exit(0)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
print("uplink: error: no run mode selected; use --cron (-c), --daemon (-d) or --foreground (-f) to run uplink. "
|
print("uplink: error: no run mode selected; use --cron (-c), --daemon (-d) or --foreground (-f) to run uplink. "
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,4 @@ class Uplink(Daemon):
|
||||||
for i in range(len(self.config["uplinks"])):
|
for i in range(len(self.config["uplinks"])):
|
||||||
t = Thread(target=self.get_data, args=(self.get_config(), i))
|
t = Thread(target=self.get_data, args=(self.get_config(), i))
|
||||||
t.start()
|
t.start()
|
||||||
if self.config["cron"]:
|
|
||||||
break
|
|
||||||
time.sleep(self.config["interval"])
|
time.sleep(self.config["interval"])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue