From e9482fbd6c797bb7cfe5f2539c6ad3dc4b659e9d Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Wed, 25 Dec 2024 12:24:12 -0800 Subject: [PATCH] linux search for kindlegen in ~/.local/bin for steam deck and more (#786) * on steam deck, search for kindlegen in ~/.local/bin * remove comment --- kcc.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/kcc.py b/kcc.py index 78978cf8..c1bb1b75 100755 --- a/kcc.py +++ b/kcc.py @@ -18,16 +18,17 @@ # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. +import os import sys +import platform + +from pathlib import Path if sys.version_info < (3, 8, 0): print('ERROR: This is a Python 3.8+ script!') sys.exit(1) -# OS specific workarounds -import os -if sys.platform.startswith('darwin'): - # prioritize KC2 since it optionally also installs KP3 +if platform.system() == 'Darwin': mac_paths = [ '/Applications/Kindle Comic Creator/Kindle Comic Creator.app/Contents/MacOS', '/Applications/Kindle Previewer 3.app/Contents/lib/fc/bin/', @@ -45,8 +46,23 @@ else: os.environ['PATH'] += os.pathsep + os.pathsep.join(mac_paths) os.chdir(os.path.dirname(os.path.abspath(__file__))) -elif sys.platform.startswith('win'): - # prioritize KC2 since it optionally also installs KP3 + +elif platform.system() == 'Linux': + if getattr(sys, 'frozen', False): + os.environ['PATH'] += os.pathsep + os.pathsep.join( + [ + str(Path.home() / ".local" / "bin"), + '/opt/homebrew/bin', + '/usr/local/bin', + '/usr/bin', + '/bin', + ] + ) + os.chdir(os.path.dirname(os.path.abspath(sys.executable))) + else: + os.chdir(os.path.dirname(os.path.abspath(__file__))) + +elif platform.system() == 'Windows': win_paths = [ os.path.expandvars('%LOCALAPPDATA%\\Amazon\\KC2'), os.path.expandvars('%LOCALAPPDATA%\\Amazon\\Kindle Previewer 3\\lib\\fc\\bin\\'), @@ -64,12 +80,7 @@ else: os.environ['PATH'] += os.pathsep + os.pathsep.join(win_paths) os.chdir(os.path.dirname(os.path.abspath(__file__))) -# Load additional Sentry configuration -# if getattr(sys, 'frozen', False): -# try: -# import kindlecomicconverter.sentry -# except ImportError: -# pass + from multiprocessing import freeze_support, set_start_method from kindlecomicconverter.startup import start