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
45import os
56import subprocess
67from collections .abc import Iterable
78
89from 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+
1016THIS_ADDON_MODULE = __name__ .split ("." )[0 ]
1117
1218
@@ -35,6 +41,7 @@ def find_config_json() -> str:
3541 return path
3642
3743
44+ @functools .cache
3845def 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+
6981if __name__ == "__main__" :
70- print (user_files_dir ())
71- print (open_file ("/etc/hosts" ))
82+ main ()
0 commit comments