Formatting and linting
This commit is contained in:
parent
5319beb735
commit
e41656355f
2 changed files with 56 additions and 22 deletions
|
|
@ -9,7 +9,13 @@ from openflexure_microscope.paths import (
|
||||||
PREFERRED_OPENFLEXURE_VAR_PATH,
|
PREFERRED_OPENFLEXURE_VAR_PATH,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import check_capture_reload, check_settings, check_picamera, check_sangaboard, check_system
|
from . import (
|
||||||
|
check_capture_reload,
|
||||||
|
check_settings,
|
||||||
|
check_picamera,
|
||||||
|
check_sangaboard,
|
||||||
|
check_system,
|
||||||
|
)
|
||||||
|
|
||||||
# Paths for suggestions
|
# Paths for suggestions
|
||||||
LOGS_PATHS = [
|
LOGS_PATHS = [
|
||||||
|
|
@ -35,12 +41,25 @@ if "-d" in sys.argv or "--debug" in sys.argv:
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
logging.debug("Testing debug logger. One two one two.")
|
logging.debug("Testing debug logger. One two one two.")
|
||||||
else:
|
else:
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
spoof = False
|
spoof = False
|
||||||
|
|
||||||
|
print()
|
||||||
|
print(bcolors.HEADER + "OpenFlexure Rescue" + bcolors.ENDC)
|
||||||
|
print()
|
||||||
|
print(
|
||||||
|
"This script attempts to identify common issues for a microscope not working properly."
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"It is not designed to identify bugs in the code, but rather configuration or setup issues."
|
||||||
|
)
|
||||||
|
print()
|
||||||
|
print("Any identified warnings [?] or errors [!] will be reported.")
|
||||||
|
print()
|
||||||
|
|
||||||
error_sources = []
|
error_sources = []
|
||||||
|
|
||||||
error_sources.extend(check_system.main())
|
error_sources.extend(check_system.main())
|
||||||
|
|
@ -51,7 +70,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
if not error_sources:
|
if not error_sources:
|
||||||
print()
|
print()
|
||||||
print(bcolors.OKGREEN + "No errors found!" + bcolors.ENDC)
|
print(bcolors.OKGREEN + "No issues found!" + bcolors.ENDC)
|
||||||
print(
|
print(
|
||||||
"That's not to say everything is fine, only that our automatic diagnostics couldn't find much."
|
"That's not to say everything is fine, only that our automatic diagnostics couldn't find much."
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,18 @@ import psutil
|
||||||
|
|
||||||
from .error_sources import WarningSource
|
from .error_sources import WarningSource
|
||||||
|
|
||||||
|
|
||||||
def internet_on():
|
def internet_on():
|
||||||
test_urls = (
|
test_urls = (
|
||||||
'https://build.openflexure.org', # Bath server
|
"https://build.openflexure.org", # Bath server
|
||||||
'https://openflexure.org' # GitHub pages
|
"https://openflexure.org", # GitHub pages
|
||||||
)
|
)
|
||||||
for url in test_urls:
|
for url in test_urls:
|
||||||
try:
|
try:
|
||||||
urlopen(url, timeout=10)
|
urlopen(url, timeout=10)
|
||||||
# If any test passes, return True
|
# If any test passes, return True
|
||||||
return True
|
return True
|
||||||
except URLError:
|
except URLError:
|
||||||
pass
|
pass
|
||||||
# If no test passed, return False
|
# If no test passed, return False
|
||||||
return False
|
return False
|
||||||
|
|
@ -22,32 +23,46 @@ def internet_on():
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
error_sources = []
|
error_sources = []
|
||||||
|
|
||||||
# Check internet
|
# Check internet
|
||||||
if not internet_on():
|
if not internet_on():
|
||||||
error_sources.append(WarningSource(
|
error_sources.append(
|
||||||
"No internet connection detected. Updates may not be available."
|
WarningSource(
|
||||||
))
|
"No internet connection detected. Updates may not be available."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Check memory
|
# Check memory
|
||||||
mem = psutil.virtual_memory()
|
mem = psutil.virtual_memory()
|
||||||
total_gb = mem.total / 1E9
|
total_gb = mem.total / 1e9
|
||||||
|
|
||||||
if total_gb <= 1:
|
if total_gb <= 1:
|
||||||
error_sources.append(WarningSource(
|
error_sources.append(
|
||||||
("Less than 1GB total memory available.",
|
WarningSource(
|
||||||
"For small scans, or control from another device, this is usually fine.",
|
(
|
||||||
"\n More complex usage may require additional resources.")
|
"Less than 1GB total memory available.",
|
||||||
))
|
"For small scans, or control from another device, this is usually fine.",
|
||||||
|
"\n More complex usage may require additional resources.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Check disks
|
# Check disks
|
||||||
data_partitions = [disk for disk in psutil.disk_partitions() if "rw" in disk.opts and disk.mountpoint != "/boot"]
|
data_partitions = [
|
||||||
|
disk
|
||||||
|
for disk in psutil.disk_partitions()
|
||||||
|
if "rw" in disk.opts and disk.mountpoint != "/boot"
|
||||||
|
]
|
||||||
for part in data_partitions:
|
for part in data_partitions:
|
||||||
usage = psutil.disk_usage(part.mountpoint)
|
usage = psutil.disk_usage(part.mountpoint)
|
||||||
if int(usage.percent) >= 90:
|
if int(usage.percent) >= 90:
|
||||||
error_sources.append(WarningSource(
|
error_sources.append(
|
||||||
(f"Disk {part.device}, at {part.mountpoint} is {int(usage.percent)}% full.",
|
WarningSource(
|
||||||
"Captures may fail to save soon.")
|
(
|
||||||
))
|
f"Disk {part.device}, at {part.mountpoint} is {int(usage.percent)}% full.",
|
||||||
|
"Captures may fail to save soon.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return error_sources
|
return error_sources
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue