Skip to content

Commit 52ee491

Browse files
committed
use bundled find_executable
1 parent 944ecea commit 52ee491

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

ajt_common

Submodule ajt_common updated 1 file

helpers/file_ops.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Copyright: Ren Tatsumoto <tatsu at autistici.org>
22
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
33

4+
import functools
45
import os
56
import subprocess
67
from collections.abc import Iterable
78

89
from anki.utils import no_bundled_libs
910

11+
try:
12+
from ..ajt_common.utils import find_executable
13+
except ImportError:
14+
from ajt_common.utils import find_executable
15+
1016
THIS_ADDON_MODULE = __name__.split(".")[0]
1117

1218

@@ -35,6 +41,7 @@ def find_config_json() -> str:
3541
return path
3642

3743

44+
@functools.cache
3845
def user_files_dir() -> str:
3946
"""Return path to the user files directory."""
4047
for parent_dir in walk_parents(__file__):
@@ -47,7 +54,6 @@ def open_file(path: str) -> None:
4754
Select file in lf, the preferred terminal file manager, or open it with xdg-open.
4855
"""
4956
from aqt.qt import QDesktopServices, QUrl
50-
from distutils.spawn import find_executable
5157

5258
if (terminal := os.getenv("TERMINAL")) and (lf := (os.getenv("FILE") or find_executable("lf"))):
5359
subprocess.Popen(
@@ -66,6 +72,11 @@ def open_file(path: str) -> None:
6672
QDesktopServices.openUrl(QUrl(f"file://{path}"))
6773

6874

75+
def main():
76+
print("config", find_config_json())
77+
print("user files", user_files_dir())
78+
print("open file", open_file("/etc/hosts"))
79+
80+
6981
if __name__ == "__main__":
70-
print(user_files_dir())
71-
print(open_file("/etc/hosts"))
82+
main()

helpers/goldendict_lookups.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
import functools
55
import os
66
import subprocess
7-
from distutils.spawn import find_executable
87
from typing import Optional
98

109
from anki.utils import is_mac
1110

11+
try:
12+
from ..ajt_common.utils import find_executable
13+
except ImportError:
14+
from ajt_common.utils import find_executable
15+
1216
GD_PROGRAM_NAME = "GoldenDict-NG"
1317
GD_MACOS_PATH = "/Applications/GoldenDict.app/Contents/MacOS/GoldenDict"
1418

1519

1620
def find_goldendict_fallback() -> Optional[str]:
17-
return is_mac and os.path.isfile(GD_MACOS_PATH) and GD_MACOS_PATH or None
21+
return GD_MACOS_PATH if (is_mac and os.path.isfile(GD_MACOS_PATH)) else None
1822

1923

2024
@functools.cache

0 commit comments

Comments
 (0)