From 04506899cc26a034139c0f0b4fce52f1f87ecf40 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 14:50:58 +0100 Subject: [PATCH] dashboard.py: mypy lints Despite it being unused I restored the `logfile` argument to `Dashboard.process()`. It's set in a call to it. Further investigation if/when we do a proper code cleanup. --- dashboard.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/dashboard.py b/dashboard.py index e98af412..bdd6e151 100644 --- a/dashboard.py +++ b/dashboard.py @@ -1,11 +1,13 @@ """Handle the game Status.json file.""" import json +import pathlib import time import tkinter as tk from calendar import timegm -from os.path import getsize, isdir, isfile, join +from os.path import getsize, isdir, isfile from sys import platform +from typing import Any, Dict from config import config from EDMCLogging import get_main_logger @@ -32,11 +34,11 @@ class Dashboard(FileSystemEventHandler): def __init__(self) -> None: FileSystemEventHandler.__init__(self) # futureproofing - not need for current version of watchdog - self.root = None - self.currentdir = None # The actual logdir that we're monitoring - self.observer = None + self.root: tk.Tk = None # type: ignore + self.currentdir: str = None # type: ignore # The actual logdir that we're monitoring + self.observer: Observer = None # type: ignore self.observed = None # a watchdog ObservedWatch, or None if polling - self.status = {} # Current status for communicating status back to main thread + self.status: Dict[str, Any] = {} # Current status for communicating status back to main thread def start(self, root: tk.Tk, started: int) -> bool: """ @@ -102,7 +104,7 @@ class Dashboard(FileSystemEventHandler): def stop(self) -> None: """Stop monitoring dashboard.""" logger.debug('Stopping monitoring Dashboard') - self.currentdir = None + self.currentdir = None # type: ignore if self.observed: logger.debug('Was observed') @@ -150,7 +152,7 @@ class Dashboard(FileSystemEventHandler): if self.observed: emitter = self.observer._emitter_for_watch[self.observed] # Note: Uses undocumented attribute - if emitter and emitter.is_alive(): + if emitter and emitter.is_alive(): # type: ignore return # Watchdog thread still running - stop polling self.root.after(self._POLL * 1000, self.poll) # keep polling @@ -165,7 +167,7 @@ class Dashboard(FileSystemEventHandler): # Can get on_modified events when the file is emptied self.process(event.src_path if not event.is_directory else None) - def process(self) -> None: + def process(self, logfile: str = None) -> None: """ Process the contents of current Status.json file. @@ -175,7 +177,7 @@ class Dashboard(FileSystemEventHandler): return try: - with open(join(self.currentdir, 'Status.json'), 'rb') as h: + with open(pathlib.Path(self.currentdir) / 'Status.json', 'rb') as h: data = h.read().strip() if data: # Can be empty if polling while the file is being re-written