From 05b056a30c40a0653fac2cf87a3346ea44699317 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Mon, 27 Dec 2021 04:24:33 +0100 Subject: [PATCH] Lot of cleanups --- uplink.py | 11 +++++------ uplink/uplink.py | 9 ++++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/uplink.py b/uplink.py index bf3233e..32ee6ed 100755 --- a/uplink.py +++ b/uplink.py @@ -110,9 +110,9 @@ if __name__ == "__main__": with open(config_path, 'r') as configfile: config_data = configfile.read() config = json.loads(config_data) - except "OSError, PermissionDenied, RuntimeError, ValueError" as err: + except Exception as err: # TODO: Replace all lines like this with generic Python logging - print(str("Uplink: Configuration Error!" + err)) + print(str("Uplink: Configuration Error!" + str(err))) sys.exit(1) try: @@ -141,8 +141,7 @@ if __name__ == "__main__": time.sleep(config["interval"]) except KeyboardInterrupt as err: print(str("uplink: program terminated by user!")) - exit(0) + sys.exit(0) else: - - print("uplink: error: no run mode selected; use --cron (-c), --daemon (-d) or --foreground (-f) to run uplink. " - "use --help for more information") + print("uplink: error: no run mode selected; use --cron (-c), --daemon (-d) or " + "--foreground (-f) to run uplink. use --help for more information") diff --git a/uplink/uplink.py b/uplink/uplink.py index aed0729..fce09b1 100644 --- a/uplink/uplink.py +++ b/uplink/uplink.py @@ -18,8 +18,9 @@ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -import pymysql + import socket +import sys import time import calendar @@ -29,12 +30,14 @@ except ImportError: from fritzconnection.lib.fritzstatus import FritzStatus from threading import Thread +import pymysql from uplink.daemon import Daemon class Uplink(Daemon): def __init__(self, pid_file, config): + super().__init__(pid_file) self.pid_file = pid_file self.config = config @@ -50,7 +53,7 @@ class Uplink(Daemon): except Exception as err: # TODO: Replace all lines like this with generic Python logging print(str("Uplink: Database connection failed: " + str(err))) - exit(1) + sys.exit(1) timestamp = calendar.timegm(time.gmtime()) local_time = time.localtime(timestamp) @@ -74,7 +77,7 @@ class Uplink(Daemon): with con.cursor() as cur: cur.execute(sql) con.commit() - exit(1) + sys.exit(1) if fc.is_connected: status = "UP"