Skip to content

Commit

Permalink
Speedwagon-497 Save System information to File exits with an unhandle…
Browse files Browse the repository at this point in the history
…d exception
  • Loading branch information
henryborchers committed Dec 7, 2023
1 parent 6520eab commit 6c9a846
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
19 changes: 17 additions & 2 deletions speedwagon/frontend/qtwidgets/dialog/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import abc
import logging
import logging.handlers
import os
import pathlib
import sys
import typing
import warnings
Expand All @@ -25,6 +27,7 @@

import speedwagon
from speedwagon.reports import ExceptionReport
from speedwagon.utils import get_desktop_path
from speedwagon.frontend.qtwidgets import logging_helpers, ui_loader
import speedwagon.frontend.qtwidgets.ui
from speedwagon.info import convert_package_metadata_to_string
Expand Down Expand Up @@ -163,19 +166,31 @@ def __init__(

def request_export_system_information(
self,
save_dialog_box=QtWidgets.QFileDialog.getSaveFileName
*_,
save_dialog_box=QtWidgets.QFileDialog.getSaveFileName,
**__,
) -> None:
"""Request system information be saved to a file."""
file, file_format = save_dialog_box(
self,
"Save File",
"speedwagon-info.txt",
os.path.join(
get_default_export_system_info_path(),
"speedwagon-info.txt"
),
"Text (*.txt)"
)
if file:
self.export_to_file.emit(file, file_format)


def get_default_export_system_info_path() -> str:
try:
return get_desktop_path()
except FileNotFoundError:
return str(pathlib.Path.home())


class AbsWorkflowProgressState(abc.ABC):
def __init_subclass__(cls) -> None:
if not hasattr(cls, "state_name") or cls.state_name is None:
Expand Down
10 changes: 5 additions & 5 deletions speedwagon/frontend/qtwidgets/gui_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import speedwagon
from speedwagon.workflow import initialize_workflows
from speedwagon import config
from speedwagon.utils import get_desktop_path
from speedwagon.tasks import system as system_tasks
from speedwagon import plugins, info
from . import user_interaction
Expand Down Expand Up @@ -943,11 +944,10 @@ def export_system_info_to_file(


def get_default_log_path() -> str:
home = pathlib.Path.home()
desktop_path = home / "Desktop"
if os.path.exists(desktop_path):
return str(desktop_path)
return str(pathlib.Path.home())
try:
return get_desktop_path()
except FileNotFoundError:
return str(pathlib.Path.home())


def export_logs_action(
Expand Down
11 changes: 10 additions & 1 deletion speedwagon/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""General module for things that don't fit anywhere else."""

import os
import pathlib
from typing import Iterator, Callable

import logging
Expand Down Expand Up @@ -45,3 +46,11 @@ def __init__(
def emit(self, record: logging.LogRecord) -> None:
"""Emit logged message to callback function."""
self.callback(logging.Formatter().format(record))


def get_desktop_path() -> str:
home = pathlib.Path.home()
desktop_path = home / "Desktop"
if os.path.exists(desktop_path):
return str(desktop_path)
raise FileNotFoundError("No Desktop folder located")

0 comments on commit 6c9a846

Please sign in to comment.