Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[830] Open Log Folder Natively #2226

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions EDMarketConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sys
import threading
import webbrowser
import tempfile
from os import chdir, environ, path
from time import localtime, strftime, time
from typing import TYPE_CHECKING, Any, Literal
Expand Down Expand Up @@ -47,8 +48,6 @@
# output until after this redirect is done, if needed.
if getattr(sys, 'frozen', False):
# By default py2exe tries to write log to dirname(sys.executable) which fails when installed
import tempfile

# unbuffered not allowed for text in python3, so use `1 for line buffering
log_file_path = path.join(tempfile.gettempdir(), f'{appname}.log')
sys.stdout = sys.stderr = open(log_file_path, mode='wt', buffering=1) # Do NOT use WITH here.
Expand Down Expand Up @@ -651,7 +650,8 @@ def open_window(systray: 'SysTrayIcon') -> None:
self.help_menu.add_command(command=lambda: self.updater.check_for_updates()) # Check for Updates...
# About E:D Market Connector
self.help_menu.add_command(command=lambda: not self.HelpAbout.showing and self.HelpAbout(self.w))
self.help_menu.add_command(command=prefs.help_open_log_folder) # Open Log Folder
logfile_loc = pathlib.Path(tempfile.gettempdir()) / appname
self.help_menu.add_command(command=lambda: prefs.open_folder(logfile_loc)) # Open Log Folder

self.menubar.add_cascade(menu=self.help_menu)
if sys.platform == 'win32':
Expand Down
24 changes: 16 additions & 8 deletions prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
import sys
import tempfile
import tkinter as tk
import webbrowser
from os import system
from os.path import expanduser, expandvars, join, normpath
from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812
from tkinter import ttk
from types import TracebackType
from typing import TYPE_CHECKING, Any, Callable, Optional, Type

import myNotebook as nb # noqa: N813
import plug
from config import appversion_nobuild, config
Expand Down Expand Up @@ -44,14 +42,21 @@ def _(x: str) -> str:

def help_open_log_folder() -> None:
"""Open the folder logs are stored in."""
logfile_loc = pathlib.Path(tempfile.gettempdir())
logfile_loc /= f'{appname}'
logger.warning(
DeprecationWarning("This function is deprecated, use open_log_folder instead. "
"This function will be removed in 6.0 or later")
)
open_folder(pathlib.Path(tempfile.gettempdir()) / appname)


def open_folder(file: pathlib.Path) -> None:
"""Open the given file in the OS file explorer."""
if sys.platform.startswith('win'):
# On Windows, use the "start" command to open the folder
system(f'start "" "{logfile_loc}"')
system(f'start "" "{file}"')
elif sys.platform.startswith('linux'):
# On Linux, use the "xdg-open" command to open the folder
system(f'xdg-open "{logfile_loc}"')
system(f'xdg-open "{file}"')


class PrefsVersion:
Expand Down Expand Up @@ -300,6 +305,9 @@ def __init__(self, parent: tk.Tk, callback: Optional[Callable]):
):
self.geometry(f"+{position.left}+{position.top}")

# Set Log Directory
self.logfile_loc = pathlib.Path(tempfile.gettempdir()) / appname

def __setup_output_tab(self, root_notebook: ttk.Notebook) -> None:
output_frame = nb.Frame(root_notebook)
output_frame.columnconfigure(0, weight=1)
Expand Down Expand Up @@ -625,7 +633,7 @@ def __setup_config_tab(self, notebook: ttk.Notebook) -> None: # noqa: CCR001
config_frame,
# LANG: Label on button used to open a filesystem folder
text=_('Open Log Folder'), # Button that opens a folder in Explorer/Finder
command=lambda: help_open_log_folder()
command=lambda: open_folder(self.logfile_loc)
).grid(column=2, padx=self.PADX, pady=0, sticky=tk.NSEW, row=cur_row)

# Big spacer
Expand Down Expand Up @@ -884,7 +892,7 @@ def __setup_plugin_tab(self, notebook: ttk.Notebook) -> None: # noqa: CCR001
plugins_frame,
# LANG: Label on button used to open a filesystem folder
text=_('Open'), # Button that opens a folder in Explorer/Finder
command=lambda: webbrowser.open(f'file:///{config.plugin_dir_path}')
command=lambda: open_folder(config.plugin_dir_path)
).grid(column=1, padx=self.PADX, pady=self.PADY, sticky=tk.N, row=cur_row)

enabled_plugins = list(filter(lambda x: x.folder and x.module, plug.PLUGINS))
Expand Down
Loading